Home as up indicator or back arrow button generally takes the user to previous activity from the current activity in the app. An arrow directing to the left is the default home as up indicator icon in the android project. To make the UI more attractive we can change home as up indicator in the android project from a default icon to custom icon.
To do so, we need an icon that suits different screen sizes of Android smartphones. You can create icons for different screen size easily from here . After creating the icon pack and downloading the icon pack, extract it and do the following.
Select the all folders from the extracted folder and paste them res folder in your android project. Now the res folder will look like below.
#1. By using the styles:
- Go to values folder and open styles.xml file and add the following line under app theme.
When we use homeAsUpIndicator, we must call setDisplayHomeAsUpEnabled(true).
- if we don’t want to call setDisplayHomeAsUpEnabled(true), we can define item as follow
- Define a tool bar in layout file, give id as “toolbar” and add the following.
Toolbar toolbar = findViewById(R.id.toolbar);
- You can also add the icon using toolbar reference.
Now home as up indicator will look like as below
We can set any icon that we like as home as up indicator but make sure that the icon supports different screen sizes otherwise the icon may blur on high-resolution devices.