android:如何删除操作栏中的后退/主页按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22313830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android: how to remove the back/home button in the action bar
提问by RyanCW
I am having difficulties trying to remove the back/home button from the action bar.
我在尝试从操作栏中删除后退/主页按钮时遇到困难。
getActionBar().setDisplayShowHomeEnabled(false); //disable back button
getActionBar().setHomeButtonEnabled(false);
In a older android phone, the back button is removed with these two code lines. However with the nexus 4, the back button still appears but is just disabled. Also I am just adding a menu item on the right that behaves like the back/home button replacing the back/home button. What am I missing?
在较旧的 android 手机中,后退按钮被这两条代码行删除。但是对于nexus 4,后退按钮仍然出现,但只是被禁用。此外,我只是在右侧添加一个菜单项,其行为类似于后退/主页按钮替换后退/主页按钮。我错过了什么?
回答by ElectronicGeek
Use getActionBar().setDisplayHomeAsUpEnabled(false)
to remove the home button from the action bar.
用于 getActionBar().setDisplayHomeAsUpEnabled(false)
从操作栏中删除主页按钮。
回答by bharv14
If you're on API level 14 or above and are not using ActionbarSherlock, this code in onCreateOptionsMenu will disable the up button, remove the left caret, and remove the icon:
如果您在 API 级别 14 或更高级别并且未使用 ActionbarSherlock,则 onCreateOptionsMenu 中的此代码将禁用向上按钮,删除左插入符号并删除图标:
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(false); // disable the button
actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}
回答by Naxos84
ElectronicGeeks answer is correct.
ElectronicGeeks 的答案是正确的。
For API lower than 11, Use:
对于低于 11 的 API,使用:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
回答by CommonsWare
To control the up affordance, use setDisplayHomeAsUpEnabled()
.
要控制向上可见性,请使用setDisplayHomeAsUpEnabled()
.
回答by Noam
None of the suggested solutions works for me.
没有一个建议的解决方案适合我。
But this one does:
但这个确实:
// Hide the back button
mActionBar.setHomeAsUpIndicator(null);
It is a kind of a hack (last resort solution), though, so showing the action bar again means setting its icon back again.
但是,这是一种黑客(最后的解决方案),因此再次显示操作栏意味着再次设置其图标。
回答by Parth Anjaria
You can use this code :
您可以使用此代码:
toggle.setDrawerIndicatorEnabled(false);
Works great for me.
对我很有用。
回答by Somsak Elect
This code work for me
这段代码对我有用
For remove navigation bar
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
用于移除导航栏
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
For remove status bar
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
用于移除状态栏
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
?But above code, it show again when you touch on screen, so if you want static state, combine this code.
?但是上面的代码,当你触摸屏幕时它会再次显示,所以如果你想要静态,结合这段代码。
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE);
回答by Rishabh
In case where you have used toolbar as Action bar:-
如果您将工具栏用作操作栏:-
Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar);
工具栏工具栏 = findViewById(R.id.toolbar); setSupportActionBar(工具栏);
Use the below code to hide navigation button:-
使用以下代码隐藏导航按钮:-
toolbar.setNavigationIcon(null);
工具栏.setNavigationIcon(null);