Display back button on action bar Ask Question

Display back button on action bar Ask Question

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.

my code.

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

the code is in onCreate.

ベストアンサー1

まあ、これは戻るボタンを表示するシンプルなものです

actionBar.setDisplayHomeAsUpEnabled(true);

そしてonOptionsItemSelectedで戻るイベントをカスタマイズすることができます

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

おすすめ記事