[英]Home Back button in Navigation bar doesn't work in my android app
After activating Navigation Up Button in Action Bar, Home Back button in Navigation bar doesn't work in my app. 激活操作栏中的向上导航按钮后,导航栏中的主页后退按钮在我的应用中不起作用。 Where am I doing wrong?
我在哪里做错了? when I click on the navigation app up button, it works.
当我单击导航应用程序向上按钮时,它可以工作。 But, Navigation back button as you can see on the pivture doesn't work...
但是,您无法在导航中看到导航后退按钮...
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;
}
First understand following things: 首先了解以下内容:
@Override
public void onBackPressed() {
super.onBackPressed();
// executed this when hardware back button is pressed
}
is called when you press back button
. 当您按下
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);
}
is called when you press back button
on Actionbar
. 当您按操作
back button
上的“ back button
时会Actionbar
。
Comment below if you have any queries.
如果您有任何疑问,请在下面评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.