[英]Program Activity Home Button to go back to previous Activity
After trying so hard to make Home button appear in my ActionBar it finally showed up, but when clicking it nothing happens.在努力让 Home 按钮出现在我的 ActionBar 中之后,它终于出现了,但是当点击它时什么也没有发生。 What method or OnClick listener should I add to make it functional.我应该添加什么方法或 OnClick 侦听器以使其正常工作。 I admit this question has been asked frequently and after going through most of them, am still not satisfied so please moderators take it easy on me, please.我承认这个问题经常被问到,在经历了大部分之后,我仍然不满意,所以请版主对我放轻松。 Anyway your help is greatly appreciated.无论如何,非常感谢您的帮助。 Here is the code这是代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
//Method to listen on the home button tap and go back to previous activity
}
@Override
protected void onUserLeaveHint() {
finish();
super.onUserLeaveHint();
}
The button in the upper left of the Action bar is the Up button .操作栏左上角的按钮是向上按钮。 If you've already added the android:parentActivityName
name to your AndroidManifest, then the system does the correct thing already - navigate you back to that parent activity as per the documentation on the onSupportNavigateUp()
method , which is the method that is triggered when that button is clicked.如果您已经将android:parentActivityName
名称添加到您的 AndroidManifest,那么系统已经做了正确的事情 - 根据onSupportNavigateUp()
方法的文档将您导航回该父活动,这是触发时的方法该按钮被点击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.