简体   繁体   English

程序活动主页按钮返回上一个活动

[英]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.

相关问题 如何转到上一个活动搜索视图后退按钮? - How to go previous activity searchview back button? go 如何通过按下带有一些数据的后退按钮返回上一个活动? - How to go back to the previous activity by pressing the back button with some data? Android Studio:在按钮上单击 go 到上一个活动(不是后退按钮) - Android Studio: On button click go to previous activity (not the back button) 如何返回上一个活动? - How to go back to the previous activity? 必须触摸两次返回按钮才能转到上一个活动 - Have to touch back button twice to go to previous activity 返回上一个片段,但不返回上一个活动 - Go back to previous fragment but not previous activity 如何在不启用操作栏上的后退按钮图标的情况下启用手机的后退按钮到 go 回到上一个活动? - How to enable back button of phone to go back to previous activity without enabling back button icon on action bar? 如何回到之前的活动状态? - how to go back to previous state of an activity? 单击主页按钮时如何将活动重定向到其先前的活动 - How to redirect a activity to its previous activity when home button is clicked 在当前活动上单击按钮(不是后退按钮)时关闭当前和上一个活动 - Closing current and previous activity on click of button(not the back button) on current activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM