安卓全屏导航栏透明度渗透到导航视图上

5
我将使用设计库导航视图全屏显示。但是导航栏和状态栏的透明度会渗透到NavigationView中。在NavigationView的右侧和顶部会出现透明黑色矩形。
我的布局:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@layout/layout_custom_view" />
</RelativeLayout>

<!-- Navigation View -->

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/navigation_view_header"
    app:menu="@menu/navigation_menu" />

MainActivity.java

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    if (Build.VERSION.SDK_INT < 16) {
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
        hideSystemUI();
    }
    setContentView(R.layout.activity_main);

    // Set NavigationView with Header and Menu
    setNavigationView();
}

/*
 * ************ SETTING FULLSCREEN TRANSIONS ************
 */

/**
 * Hide Status and Navigation bars
 */
public void hideSystemUI() {
    if (Build.VERSION.SDK_INT >= 16) {
        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.
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                // Views can use nav bar space if set
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                // hide nav bar
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                // hide status bar
                | View.SYSTEM_UI_FLAG_FULLSCREEN 
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                );
    }

}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        hideSystemUI();
    }
}
1个回答

5

移除 View.SYSTEM_UI_FLAG_LAYOUT_STABLE 可以解决这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接