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

后端 未结 3 1698

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);
    }
    

提交回复
热议问题