安卓--完全隐藏状态和导航栏的应用程序的导航抽屉和应用程序栏。

问题描述 投票:2回答:1

如何动态隐藏状态和导航栏?彻底?

该应用包含一个常规的导航抽屉,有appbar工具栏和FAB按钮。

当切换到全屏时,该 内容 的导航和状态栏被卷走。屏幕上留下两个空条。我想让这些空条隐藏起来。

我在屏幕上创建了一个 最小的演示程序. 左边是常规应用。当按下fab的时候,应用应该是全屏显示的。

enter image description here

我如何才能让这些条形图隐藏起来?

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

更新了第二个解决方案:

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

如果你在状态导航条的显示和隐藏方面仍有问题,这个解决方案可能会帮助你。

完全隐藏条形图。

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 android-layout android-navigation-bar
1个回答
1
投票

更新内容

问题出在你的布局文件上。我只是设置了 android:fitsSystemWindows=false 来解决这个问题。我做了一个 拉动请求 到你的 repo,我想这可以解决你的问题。

enter image description here


你应该遵循以下官方文档。


隐藏Android 4.0及以下版本的状态栏

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);
    }
    ...
}

在Android 4.1和更高版本上隐藏状态栏。

    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();

隐藏导航栏

    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);

0
投票

进入values>样式

现在在应用主题中使用

让导航栏超越

<item name="android:windowTranslucentNavigation">true</item>

要删除它,使其颜色与你的布局相匹配

<item name="android:navigationBarColor">@color/white</item>

或者试试这个

public void FullScreencall() {
    if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
        View v = this.getWindow().getDecorView();
        v.setSystemUiVisibility(View.GONE);
    } else if(Build.VERSION.SDK_INT >= 19) {
        //for new api versions.
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(uiOptions);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.