显示回到操作栏按钮按钮、操作

2023-09-12 01:50:01 作者:我下线你上线我活着你去死

我想显示操作栏返回按钮移动previous页/活动或到主页(第一开口)。 我不能做到这一点。

I'm trying to display a Back button on the Action bar to move previous page/activity or to the main page (first opening). And I can not do it.

我的code。

ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);

在code是在的onCreate

推荐答案

嗯,这是简单的显示后退按钮

well this is simple one to show back button

actionBar.setDisplayHomeAsUpEnabled(true);

然后就可以自定义在onOptionsItemSelected后面的事件

and then you can custom the back event at onOptionsItemSelected

case android.R.id.home:
this.finish();
return true;