@Override
protected void onCreate(Bundle savedInstanceState) {
······
//拿到标题栏
ActionBar actionBar = getSupportActionBar();
//显示左上角箭头返回
actionBar.setDisplayHomeAsUpEnabled(true);
//为标题设置显示图标
actionBar.setDisplayShowHomeEnabled(true);
//设置图标
actionBar.setLogo(R.drawable.ic_baseline_settings_24);
//显示Logo
actionBar.setDisplayUseLogoEnabled(true);
}
//选中哪一项执行哪一项的操作
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
//拿到每一项的Id
int itemId = item.getItemId();
switch (itemId){
······
case android.R.id.home:
//销毁当前页面 实现返回
this.finish();
break;
}
return super.onOptionsItemSelected(item);
}
标签:返回,actionBar,item,按钮,Override,左上角,true
From: https://www.cnblogs.com/loulan/p/16974534.html