setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) 不起作用 [英] setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) does not work

查看:22
本文介绍了setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在与 setSystemUiVisibility() 斗争以尝试隐藏软导航按钮一段时间(对于视频播放器).它似乎不像宣传的那样工作.这是我的代码,在一个可见的 FrameLayout 中.

I've been battling with setSystemUiVisibility() to try to hide the soft navigation buttons for a while (for a video player). It does not seem to work as advertised. Here is my code, inside a visible FrameLayout.

void setNavVisibility(boolean visible)
{
    int newVis = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    if (!visible)
    {
        newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    }
    setSystemUiVisibility(newVis);
}

对 SDK 示例稍作修改:

Slightly modified from the SDK example:

    void setNavVisibility(boolean visible) {
        int newVis = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | SYSTEM_UI_FLAG_LAYOUT_STABLE;
        if (!visible) {
            newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN
                    | SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        }

被调用时不要做任何事情.当我从不同的 View 调用它们时,我取得了一些成功,但是文档没有提到您正在调用的 View 有任何影响吗?我认为这里的文档(出人意料地)有些缺乏.有谁知道到底发生了什么?

Neither do anything when called. I had some success when I called them from a different View, but the documentation doesn't mention that the View you are calling from has any effect? I assume that the documentation is (surprise surprise) somewhat lacking here. Does anyone know what's really going on?

推荐答案

嗯显然我 重复了我自己的问题! 但无论如何我找到了答案:阅读源代码后——这通常是在 Android 领域找到问题的唯一方法——我发现了以下未记录的事实:

Hmm apparently I duplicated my own question! But anyway I found the answer: After reading the source code - which is often the only way to find things out in Android-land - I discovered the following undocumented fact:

setSystemUiVisibility() 仅在您调用它的视图可见时才有效!

甚至更多:调用 setSystemUiVisibility() 的视图必须保持可见,导航栏才能保持隐藏.感谢您记录这些家伙,真的很棒.

Even more: The view in which you call setSystemUiVisibility() must remain visible for the nav bar to remain hidden. Thanks for documenting that guys, really great.

这里是相关代码,在View.java中.

Here is the relevant code, in View.java.

void performCollectViewAttributes(AttachInfo attachInfo, int visibility) {
    if ((visibility & VISIBILITY_MASK) == VISIBLE) {
        if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) {
            attachInfo.mKeepScreenOn = true;
        }
        attachInfo.mSystemUiVisibility |= mSystemUiVisibility;
        ListenerInfo li = mListenerInfo;
        if (li != null && li.mOnSystemUiVisibilityChangeListener != null) {
            attachInfo.mHasSystemUiListeners = true;
        }
    }
}

这篇关于setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆