Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android全屏导航栏透明度显示在导航视图上_Android_Uinavigationbar_Navigationview_Android Fullscreen_Android Statusbar - Fatal编程技术网

Android全屏导航栏透明度显示在导航视图上

Android全屏导航栏透明度显示在导航视图上,android,uinavigationbar,navigationview,android-fullscreen,android-statusbar,Android,Uinavigationbar,Navigationview,Android Fullscreen,Android Statusbar,我正在全屏使用design library导航视图。但是导航栏和状态栏的透明度会渗透到NavigationView。透明的黑色矩形出现在NavigationView的右侧和顶部 我的布局 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:a

我正在全屏使用design library导航视图。但是导航栏和状态栏的透明度会渗透到
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();
    }
}
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG\u保持屏幕打开);
如果(Build.VERSION.SDK_INT<16){
getWindow().requestFeature(Window.FEATURE\u NO\u TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,
WindowManager.LayoutParams.FLAG(全屏);
}否则{
hideSystemUI();
}
setContentView(R.layout.activity_main);
//使用标题和菜单设置NavigationView
setNavigationView();
}
/*
***********设置全屏传输************
*/
/**
*隐藏状态栏和导航栏
*/
公共void hideSystemUI(){
如果(Build.VERSION.SDK_INT>=16){
View decorView=getWindow().getDecorView();
//隐藏导航栏和状态栏。
//SYSTEM_UI_FLAG_全屏仅在Android 4.1和
//更高,但作为
//一般来说,你应该设计你的应用程序来隐藏状态栏
//每当你
//隐藏导航栏。
decorView.setsystemivilibility(
View.SYSTEM\u UI\u FLAG\u布局\u稳定
//视图可以使用导航栏空间(如果已设置)
|View.SYSTEM\u UI\u FLAG\u布局\u隐藏\u导航
|View.SYSTEM\u UI\u FLAG\u布局\u全屏显示
//隐藏导航条
|View.SYSTEM\u UI\u FLAG\u HIDE\u导航
//隐藏状态栏
|View.SYSTEM\u UI\u FLAG\u全屏显示
|View.SYSTEM\u UI\u FLAG\u沉浸式\u粘性
);
}
}
@凌驾
WindowFocusChanged上的公共无效(布尔hasFocus){
super.onWindowFocusChanged(hasFocus);
如果(hasFocus){
hideSystemUI();
}
}

删除
视图。系统\u UI\u标志\u布局\u稳定
解决了这个问题