如何像处理后退导航一样处理向上导航?
是否有类似返回导航的向上导航方法 (onBackPressed()
)?
或者当我按下向上导航时,我可以编写 finish()
方法吗?
最佳答案
假设“向上导航”是指点击应用程序图标,您需要在 Activity 中覆盖 onOptionsItemSelected()
并像这样处理它:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// 'home' is the id for the icon click in the action bar (i.e. up/back).
if (item.getItemId() == android.R.id.home) {
// do your thing and return true
return true;
}
return super.onOptionsItemSelected(item);
}
关于java - 像返回导航一样处理操作栏中的向上导航。如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27675492/