Android 如何在平板电脑中隐藏系统导航栏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12605266/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:09:59  来源:igfitidea点击:

How to Hide System Navigation Bar in Tablets?

androidandroid-softbuttons

提问by John

At my Tablet, it has following bar to control back, home etc. (I don't know the correct name, status bar? control bar? Action bar? or other)

在我的平板电脑上,它有以下栏来控制返回,主页等(我不知道正确的名称,状态栏?控制栏?操作栏?或其他)

In program, it use following method to have a full screen.

在程序中,它使用以下方法来获得全屏。

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.PROGRESS_INDETERMINATE_OFF);

But I don't know why the bar still in here. Because of it, I can't have the correct screen size.

但我不知道为什么酒吧还在这里。因此,我无法拥有正确的屏幕尺寸。

Who can tell me how to remove it?

谁能告诉我怎么去掉?

The Bar

酒吧

回答by David Rettenbacher

There seems to be a UNDOCUMENTEDflagfor this:

似乎有一个UNDOCUMENTED标志

yourGreatView.setSystemUiVisibility(8);
  • no black footer("hidden" system bar)
  • resizes view if keyboard shows up(no overlapped inputs)
  • 没有黑色页脚(“隐藏”系统栏)
  • 如果键盘出现,则调整视图大小(无重叠输入)

Verified on Android 4.1.2 (API 16)
Verified on Android 4.1.1 (API 16)
Verified not working on Android 4.0.4 (API 15)

在 Android 4.1.2 (API 16) 上
验证在 Android 4.1.1 (API 16) 上
验证在 Android 4.0.4 (API 15) 上不工作

(all tablets)

(所有平板电脑)

回答by Swayam

In Tablets running Android 4+, it is not possible to hide the System / Navigation Bar.

在运行 Android 4+ 的平板电脑中,无法隐藏System / Navigation Bar

From documentation(Controls for system UI visibilitysection) :

文档系统 UI 可见性部分的控件):

The SYSTEM_UI_FLAG_HIDE_NAVIGATIONis a new flag that requests the navigation bar hide completely. Be aware that this works only for the navigation bar used by some handsets (it does not hide the system bar on tablets).

SYSTEM_UI_FLAG_HIDE_NAVIGATION是一个新标志,要求完全隐藏导航栏。请注意,这仅适用于某些手机使用的导航栏(它不会隐藏平板电脑上的系统栏)。

However, you could try to dim the system bar as done sometimes during gaming and video playback.

但是,您可以尝试像有时在游戏和视频播放期间一样使系统栏变暗。

The SYSTEM_UI_FLAG_LOW_PROFILEflag replaces the STATUS_BAR_HIDDEN flag. When set, this flag enables “low profile" mode for the system bar or navigation bar. Navigation buttons dim and other elements in the system bar also hide. Enabling this is useful for creating more immersive games without distraction for the system navigation buttons.

SYSTEM_UI_FLAG_LOW_PROFILE标志取代了 STATUS_BAR_HIDDEN 标志。设置后,此标志为系统栏或导航栏启用“低调”模式。导航按钮变暗,系统栏中的其他元素也会隐藏。启用此功能对于创建更加身临其境的游戏非常有用,而不会分散系统导航按钮的注意力。

回答by emidander

In Android 4.4 and above you can completely hide the navigation bar and have it remain hidden using a combination of fullscreen and immersion:

在 Android 4.4 及更高版本中,您可以完全隐藏导航栏,并使用全屏和沉浸式的组合使其保持隐藏状态:

@Override
protected void onResume() {
    super.onResume();

    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}

回答by richmb

A very nuclear option is to just delete the SystemUI.apk from /system/app/. But warning this will remove it from the tablet completely. I'm doing this on a tablet i'm using for a front panel kiosk, then i set the tablet to boot into my app.

一个非常核心的选择是从 /system/app/ 中删除 SystemUI.apk。但是警告这会将其从平板电脑中完全删除。我在用于前面板信息亭的平板电脑上执行此操作,然后我将平板电脑设置为启动到我的应用程序。

回答by Andreu

public class Utils {

public static void hideNavigations(Activity context) {
    View decorView = context.getWindow().getDecorView();
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}

}

}

In your Activity:

在您的活动中:

@Override
protected void onResume() {
    super.onResume();
    Utils.hideNavigations(this);
}

回答by Led Machine

As other people say use the command "pm disable com.android.systemui" in root mode, so the following code execute this command in your android app, just call the following method, your tablet needs to be rooted.

正如其他人所说在root模式下使用命令“pm disable com.android.systemui”,因此以下代码在您的android应用程序中执行此命令,只需调用以下方法,您的平板电脑需要root。

private void hideNavigationBar(){
        try {
            Process process = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(process.getOutputStream());
            os.writeBytes("pm disable com.android.systemui\n");
            os.flush();
            os.writeBytes("exit\n");
            os.flush();
            process.waitFor();
            //////////////////////////////////////
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

This code hide the navigation bar on the android system, to reappear system bar use "pm enable com.android.systemui" instead of "pm disable com.android.systemui" in the previous code.

此代码隐藏了android系统上的导航栏,要重新出现系统栏,请使用“pm enable com.android.systemui”而不是之前代码中的“pm disable com.android.systemui”。

回答by Sunita

Below code worked for me -

下面的代码对我有用 -

You can write it in onCreate() or onResume( if needed)

您可以在 onCreate() 或 onResume( 如果需要) 中编写它

getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_IMMERSIVE
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

回答by Ferdau

Since the system bar is used to navigate in android there is not an easy way to achieve this, you can dissable/dim the controls:

由于系统栏用于在 android 中导航,因此没有简单的方法可以实现这一点,您可以禁用/调暗控件:

View v = findViewById(R.id.view_id);
v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);

But you can get the size of the screen without the systembar (not sure from what version, I think 3.1)

但是你可以在没有系统栏的情况下获得屏幕的大小(不确定从哪个版本开始,我认为是 3.1)

Method rawW = Display.class.getMethod("getRawWidth");
Method rawH = Display.class.getMethod("getRawHeight");
int width = (Integer)mGetRawW.invoke(dp);
int height = (Integer)mGetRawH.invoke(dp);

If your app has root access there is also a way to achieve it: http://ppareit.github.com/HideBar/

如果您的应用程序具有 root 访问权限,还有一种方法可以实现它:http: //ppareit.github.com/HideBar/

回答by PiyushMishra

You can't hide it but you can simply disable it, except home. Try this link.. Using SYSTEM_UI_FLAG_LOW_PROFILE you can dim your system bar and using onWindowFocusChanged()can take the focus and collapse it.

你不能隐藏它,但你可以简单地禁用它,除了家。试试这个链接。. 使用 SYSTEM_UI_FLAG_LOW_PROFILE 您可以使系统栏变暗,使用onWindowFocusChanged()可以获取焦点并将其折叠。