What is the ID of the back arrow drawable in the ActionBar?

hmuss picture hmuss · Jun 28, 2017 · Viewed 11.3k times · Source

The following code causes a back arrow to appear in the ActionBar:

getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

I'm looking for the resource ID of the arrow drawable, i.e. android.R.drawable.xxx. The reason I need this ID is so that I can manually set an identical arrow (size & colour) elsewhere in my app.

I tried making my own drawable and using that but the size was different from the one in the ActionBar.

Answer

VorteXavier picture VorteXavier · Jan 19, 2018

If you have the support library in your project, you can make a back button in any place in your applicaction like this:

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="?attr/homeAsUpIndicator"
        android:background="?attr/selectableItemBackgroundBorderless"/>

Specifically the resource for the back arrow is ?attr/homeAsUpIndicator.