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

后端 未结 3 1699

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

getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsU         


        
相关标签:
3条回答
  • 2021-02-19 19:42

    The id of the back button in Toolbar is

    android.R.id.home

    You can take action from onOptionsItemSelected Method on Activity.

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            //Do your task here.
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    0 讨论(0)
  • 2021-02-19 19:45

    You can easily create a back arrow using Android asset studio.

    Click on res folder and then right click on drawable -> New -> Vector Asset

    0 讨论(0)
  • 2021-02-19 19:56

    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.

    0 讨论(0)
提交回复
热议问题