how to override action bar back button in android?

前端 未结 10 716
孤街浪徒
孤街浪徒 2020-11-30 03:40

I want to customize the activity back button in action bar, not in hard key back button. I have overriden the onBackPressed() method. It works with my emulator

10条回答
  •  鱼传尺愫
    2020-11-30 04:18

    There are several ways how to set up back button in bar:

    1) method .setDisplayHomeAsUpEnabled(true); will do it, and then you can simply override android.R.id.home

    2) adding in Android Manifest, but in this case you can not override android.R.id.home in OnOptionsMenuSelected.

    .. for those who wonder why it doesn't work for them...

提交回复
热议问题