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

試著忘記壹切 提交于 2019-12-05 05:34:41

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.

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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!