android-layout - Android-完全隐藏具有抽屉导航和应用程序栏的应用程序的状态和导航栏

标签 android-layout android-actionbar android-statusbar android-fullscreen android-navigation-bar

如何动态隐藏状态和导航栏完全

该应用程序包含一个带有应用程序栏/工具栏和FAB按钮的常规抽屉导航。

切换到全屏时,导航和状态栏的内容会被滚动。屏幕上留下两个空白栏。我要隐藏那些空的酒吧。

我创建了一个minimal demo app。左侧是常规应用。在工厂上推时,该应用应全屏显示。

enter image description here

如何获得隐藏的酒吧?

问题:请写出最小演示项目中需要哪些更改?

更新了第二个解决方案:

@Roaim提供的GREAT解决方案有效。必要的是将android:fitsSystemWindows布局属性设置为false。

如果您仍然无法显示和隐藏状态/导航栏,则此solutin可能会为您提供帮助。

完全隐藏栏:

public static void hideSystemUI() {
    if (getSupportActionBar() != null) {
        getSupportActionBar().hide();
    }
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE
                    | 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);
}

并显示所有条形:
public static void showSystemUI() {
    if (getSupportActionBar() != null) {
        getSupportActionBar().show();
    }
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}

最佳答案

更新

问题出在您的布局文件上。我只是设置android:fitsSystemWindows=false来解决此问题。我为您的仓库做了一个pull request,我认为可以解决您的问题。

enter image description here

您应该遵循以下官方文档:

  • Hide the status bar
  • Hide the navigation bar


  • Hide the Status Bar on Android 4.0 and Lower


    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // If the Android version is lower than Jellybean, use this call to hide
            // the status bar.
            if (Build.VERSION.SDK_INT < 16) {
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
            setContentView(R.layout.activity_main);
        }
        ...
    }
    

    Hide the Status Bar on Android 4.1 and Higher


        View decorView = getWindow().getDecorView();
        // Hide the status bar.
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        // Remember that you should never show the action bar if the
        // status bar is hidden, so hide that too if necessary.
        ActionBar actionBar = getActionBar();
        actionBar.hide();
    

    Hide the Navigation Bar


        View decorView = getWindow().getDecorView();
        // Hide both the navigation bar and the status bar.
        // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
        // a general rule, you should design your app to hide the status bar whenever you
        // hide the navigation bar.
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                      | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    

    关于android-layout - Android-完全隐藏具有抽屉导航和应用程序栏的应用程序的状态和导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61573305/

    相关文章:

    android - 条目名称 'res/color/material_on_surface_disabled.xml' 发生冲突

    android - 形状中的色调和纯色有什么区别?

    android - Cordova:StatusBar 插件适用于模拟器但不适用于设备

    java - 将微调项目存储在字符串值中

    android - 为什么 GridView 中的适配器不更新其内容?

    android - 操作栏后退按钮无法按需运行

    android - 新的 Android 工具栏 : Unhide/Hide Menu Action Icons when Logged In Logged Out

    ios - 如何删除 ActionBar 上 ActionContent 和 NavigationContent 的边框

    android - Flutter,Android - 是否可以更改初始(启动)屏幕上的状态栏颜色?

    c# - 在 Unity3D 场景中更改 Android 状态栏颜色