我创建了一个具有导航视图的应用程序。
当应用程序以全屏显示时,我打开该导航视图,该导航视图向我显示了导航视图顶部的黑色覆盖层,并且还向我显示了屏幕底部和导航视图底部之间的间隙。为此。
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
...
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
tools:ignore="RtlSymmetry">
<!--PlayList Layout-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcvVideoPlaylist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:fitsSystemWindows="false"
tools:listitem="@layout/item_video_playlist" />
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
任何人都可以给我解决方案,以从导航视图中删除该叠加层,并删除该导航视图中的空白
您可以使用此代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/rv">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
您可以将此类用于全屏Activity
,其中状态和导航视图不会渗入NavigationView。
我遇到了同样的问题,尝试了系统标志的组合,找到了正确的组合。
//删除渗色透明到导航视图上
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
这是我的全屏活动。
public class FullScreenAppCompatActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT < 14) {
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
hideSystemUI();
}
}
/*
* ************ SETTING FULLSCREEN TRANSITIONS ************
*/
/**
* Hide Status and Navigation bars
*/
@SuppressLint("InlinedApi")
public void hideSystemUI() {
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.
// Navigation bar hiding: Backwards compatible to ICS.
// SELECTIVE FLAGS final code: 5890
// setSelectedFlags(decorView);
// NO SELECTION OF SDK_INT flag final cod: 5894
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
// Navigation bar hiding: Backwards compatible to ICS.
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
// Status bar hiding: Backwards compatible to Jellybean
| View.SYSTEM_UI_FLAG_FULLSCREEN
// Immersive mode: Backward compatible to KitKat.
// Note that this flag doesn't do anything by itself, it only
// augments the behavior
// of HIDE_NAVIGATION and FLAG_FULLSCREEN. For the purposes of
// this sample
// all three flags are being toggled together.
// Note that there are two immersive mode UI flags, one of which
// is referred to as "sticky".
// Sticky immersive mode differs in that it makes the navigation
// and status bars
// semi-transparent, and the UI flag does not get cleared when
// the user interacts with
// the screen.
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
// Removes bleeding transparency onto navigation-view
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
private void setSelectedFlags(View decorView) {
int selectedFlags = 0;
if (Build.VERSION.SDK_INT >= 14) {
selectedFlags ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Toast.makeText(getApplicationContext(), "View.SYSTEM_UI_FLAG_HIDE_NAVIGATION flag " + selectedFlags,
Toast.LENGTH_SHORT).show();
}
// Status bar hiding: Backwards compatible to Jellybean
if (Build.VERSION.SDK_INT >= 16) {
selectedFlags ^= (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);
Toast.makeText(getApplicationContext(), "View.SYSTEM_UI_FLAG_FULLSCREEN flag " + selectedFlags,
Toast.LENGTH_SHORT).show();
}
if (Build.VERSION.SDK_INT >= 19) {
selectedFlags ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
Toast.makeText(getApplicationContext(), "Final SELECTED flag " + selectedFlags, Toast.LENGTH_SHORT).show();
decorView.setSystemUiVisibility(selectedFlags);
int currentVisibility = getWindow().getDecorView().getSystemUiVisibility();
Toast.makeText(getApplicationContext(), "Initial visibility flag " + currentVisibility, Toast.LENGTH_SHORT)
.show();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
hideSystemUI();
}
}
}