简体   繁体   English

检测Android上的软导航栏并隐藏导航栏

[英]Detecting Soft Navigation Bar on Android and hiding Navigation Bar

Now before anyone marks question as a duplicate, please read the question carefully.现在,在任何人将问题标记为重复之前,请仔细阅读问题。 I have tried each and every current answer on Stack Overflow.我已经尝试了 Stack Overflow 上的每一个当前答案。

In general, I want to know how to detect if there exists any soft Navigation Bar at the bottom of the screen on the user's device.一般来说,我想知道如何检测用户设备屏幕底部是否存在任何软导航栏。

Now,现在,

1) I have seen an answer where people check the maximum screen size, see which app/activity is being displayed and then, depending upon the result, decide whether there is a soft Nav Bar not. 1)我看到一个答案,人们检查最大屏幕尺寸,查看正在显示哪个应用程序/活动,然后根据结果决定是否有软导航栏。 This will not be reliable for devices with a notch.这对于有缺口的设备来说是不可靠的。

2) I'm not interested to know if there is a hardware Nav Bar or not. 2)我不想知道是否有硬件导航栏。 A Soft Nav Bar is a must because:软导航栏是必须的,因为:

a.一种。 In my actual device, there are no hardware Nav Bars and no soft Nav Bar either.在我的实际设备中,没有硬件导航栏,也没有软导航栏。 Several phone nowadays uses gestures to navigate.现在有几款手机使用手势来导航。

b.But in my emulator, there are nav bar.但是在我的模拟器中,有导航栏。 There are soft Nav Bars.有软导航栏。

To hide them I use this code:为了隐藏它们,我使用以下代码:

int uiOptionsForDevicesWithoutNavBar = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_FULLSCREEN
        |  View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptionsForDevicesWithoutNavBar);

Now, this works like a charm.现在,这就像一个魅力。 Waalaa, Nav Bars are hidden. Waalaa,导航栏是隐藏的。 But here comes the problem on my actual phone.但是我的实际手机出现了问题。 It uses Gestures.它使用手势。 On my first swipe for Back, the notification bar appears and then on the next immediate swipe for Back, the required back action takes place.在我第一次滑动返回时,会出现通知栏,然后在下一次立即滑动返回时,会发生所需的返回操作。

But if I do this:但如果我这样做:

int uiOptionsForDevicesWithoutNavBar = View.SYSTEM_UI_FLAG_FULLSCREEN
        |  View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptionsForDevicesWithoutNavBar);

Then it works properly on my physical device, but the Nav Bar doesn't get hidden on the emulator, which is obvious because the main flag that hides it is not there.然后它在我的物理设备上正常工作,但导航栏没有隐藏在模拟器上,这很明显,因为隐藏它的主标志不在那里。

So I want to run different flags for different types of phones depending upon whether the device has on-screen Soft Nav Bars or not.所以我想根据设备是否有屏幕软导航栏为不同类型的手机运行不同的标志。

Hence, I'd like to know how to detect if there are on screen soft Nav Bars or not.因此,我想知道如何检测屏幕上是否有软导航栏。

Also, if there is a better way to do it, please help me.另外,如果有更好的方法,请帮助我。

public boolean hasNavigationBar(Resources resources) {
        int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
        return id > 0 && resources.getBoolean(id);
    }

This method will read from the Android system the value config_showNavigationBar boolean.此方法将从 Android 系统读取值 config_showNavigationBar 布尔值。 Many OEMs use this value when hiding or showing the navigation bar like Samsung.许多 OEM 在隐藏或显示导航栏(如三星)时使用此值。

Note: many third party apps are hiding the navigation bar via a tricky ADB command , I still didn't find a way to detect this , please see this question注意:许多第三方应用程序通过一个棘手的 ADB 命令隐藏导航栏,我仍然没有找到检测方法,请参阅此问题

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

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