隐藏状态栏时,它变成黑色
When hide State Bar, it turns black
I am trying to hide (state bar and navigation bar) on my splash
screen , but it turned to black state like photo below.
我的风格代码:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:navigationBarColor">@color/color_navigation_bar</item>
</style>
还有我的 java 代码:
private void hideSystemUI() {
Window window = this.getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { // API 30
window.setDecorFitsSystemWindows(false);
} else {
// window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
我也在尝试使用此代码,但仍然是黑色的:
this.getWindow().getDecorView().setSystemUiVisibility(
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 // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
Any one can help me ?
这个answer解决了我的问题。
完成这三个部分,就会完成:
1- show/hide 系统 UI 在 Activity
中的方法
private fun hideSystemUI() {
sysUIHidden = true
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // Hide nav bar
or View.SYSTEM_UI_FLAG_FULLSCREEN // Hide status bar
)
}
private fun showSystemUI() {
sysUIHidden = false
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // layout Behind nav bar
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // layout Behind status bar
)
}
2- 确保在您的 xml 布局的根视图中
android:fitsSystemWindows="false"
3- 全屏样式 Activity 将在 status/navigation 栏显示时提供半透明背景:
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
<item name="android:statusBarColor">#50000000</item>
<item name="android:navigationBarColor">#50000000</item>
// Important to draw behind cutouts
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/sysTransparent</item>
</style>
I am trying to hide (state bar and navigation bar) on my splash screen , but it turned to black state like photo below.
我的风格代码:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:navigationBarColor">@color/color_navigation_bar</item>
</style>
还有我的 java 代码:
private void hideSystemUI() {
Window window = this.getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { // API 30
window.setDecorFitsSystemWindows(false);
} else {
// window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
我也在尝试使用此代码,但仍然是黑色的:
this.getWindow().getDecorView().setSystemUiVisibility(
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 // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
Any one can help me ?
这个answer解决了我的问题。
完成这三个部分,就会完成:
1- show/hide 系统 UI 在 Activity
中的方法private fun hideSystemUI() {
sysUIHidden = true
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // Hide nav bar
or View.SYSTEM_UI_FLAG_FULLSCREEN // Hide status bar
)
}
private fun showSystemUI() {
sysUIHidden = false
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // layout Behind nav bar
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // layout Behind status bar
)
}
2- 确保在您的 xml 布局的根视图中
android:fitsSystemWindows="false"
3- 全屏样式 Activity 将在 status/navigation 栏显示时提供半透明背景:
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
<item name="android:statusBarColor">#50000000</item>
<item name="android:navigationBarColor">#50000000</item>
// Important to draw behind cutouts
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/sysTransparent</item>
</style>