简体   繁体   English

隐藏Android上的主页按钮和后退按钮

[英]Hidding home button and back button on Android

In styles I've 在我的风格

<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>

and in the manifest file, in application I've specified my theme, but home button and back button are still visible, what should I do? 在清单文件中的应用程序中,我已经指定了主题,但是主页按钮和后退按钮仍然可见,我该怎么办?

You must use Immersive feature of android. 您必须使用android的Immersive功能。 Immersive mode will be only working on devices with KitKat and higher. 沉浸模式仅适用于具有KitKat和更高版本的设备。 This, what is weird on your side, is fact, that basing on your words, you cannot even get these flags like this: 在您这边,这很奇怪,事实是,基于您的话语,您甚至无法获得如下这些标志:

View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;

(or part of them). (或其中的一部分)。 If it is this way, then it is looking, that your compileSdkVersion is lower, than it should be. 如果是这种方式,则说明您的compileSdkVersion低于实际值。 On start I would advise you to update compileSdkVersion. 一开始,我建议您更新compileSdkVersion。

When you will do this, and you would like to use these flags please in places, where you want to use immersive mode add conditions, that will be looking like this: 当您执行此操作时,如果您想在沉浸式添加条件下使用这些标志,请如下所示:

if (Build.VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
    int UI_OPTIONS = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
    getWindow().getDecorView().setSystemUiVisibility(UI_OPTIONS);
}

Then it should not mess on older OS. 这样就不会在较旧的OS上混乱。

Use the following two way to achieve what you need 使用以下两种方法来实现您所需要的

  • getActionBar().setDisplayHomeAsUpEnabled(false) to remove the home button from the action bar. getActionBar()。setDisplayHomeAsUpEnabled(false)从操作栏中删除主页按钮。
  • ActionBar().setHomeAsUpIndicator(null); ActionBar()。setHomeAsUpIndicator(null); getSupportActionBar().setHomeAsUpIndicator(null); getSupportActionBar()。setHomeAsUpIndicator(null); i prefer you use the first 1 我希望您使用前1个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM