导航栏中的主页后退按钮在我的 android 应用中不起作用

Home Back button in Navigation bar doesn't work in my android app

激活操作栏中的导航向上按钮后,导航栏中的主页后退按钮在我的应用程序中不起作用。我哪里做错了?当我点击导航应用程序向上按钮时,它起作用了。但是,您在图片上看到的导航后退按钮不起作用...

Back Button

enter image description here

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    super.onOptionsItemSelected(item);
    switch (item.getItemId()) {
        case R.id.action_email:
            emailMenuItem();
            break;
        case R.id.action_settings:
            settingsMenuItem();
            break;
    }
    return true;
}

首先了解以下内容:

@Override
public void onBackPressed() {
    super.onBackPressed();
    // executed this when hardware back button is pressed
}
当您按下 back button 时调用

AND

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch(id) {
        case android.R.id.home:
            // executed this when back button on Actionbar is pressed
            return true;
        default:
            break;
    }
    return super.onOptionsItemSelected(item);
}
当您在 Actionbar 上按 back button 时调用

Comment below if you have any queries.