如何删除顶部状态栏黑色背景 [英] How to remove top status bar black background
问题描述
我想创建一个TRUE全屏活动,但是屏幕顶部始终有一个黑色状态栏.Android 9.0.
I'd like to create a TRUE fullscreen activity, but there is always a black status bar on screen top. Android 9.0.
我已经尽我所能在Google和具有类似工作的现有Apps上找到的所有内容.清单,代码,样式,AS示例全屏活动均已尝试.
I've tried almost all I can find with Google and existing Apps with similar jobs. Manifest, code, style, AS sample fullscreen activity, all were tried.
styles.xml:
styles.xml:
<style name="AppThemeA" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
清单:
<activity android:name=".ScreenActivity" android:theme="@style/AppThemeA" />
布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/rootLayout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Kotlin(注释行尝试并失败):
Kotlin (commented lines are tried and failed):
class ScreenActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
//setTheme(R.style.AppThemeDetector)
super.onCreate(savedInstanceState)
//window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
//window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
//window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_FULLSCREEN
/*
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_FULLSCREEN
)*/
setContentView(R.layout.activity_screen_detector)
...
}
}
预期结果:
我实际上得到了什么:
What I actually got:
[[[[[Solution]]]]
[[[[ Solution ]]]]
找到了造成这种情况的原因.您应该在设置"->显示"中将应用程序"设置为全屏应用程序".
Found what caused this. You should set the App to FullScreen App in Settings -> Display.
https://www.gottabemobile.com/how-to-enable-full-screen-apps-on-galaxy-s10
如此固定.感谢您的所有帮助.
So fixed. Thanks for all your help.
推荐答案
我在通过缺口或切口区域显示内容时遇到了问题.在文档中找到了这个
I had a problem with displaying content through the notch or the cutout area. Found this in the docs:
LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES-内容以纵向和横向模式呈现到剪切区域.
LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES - Content renders into the cutout area in both portrait and landscape modes.
对我来说,关键是活动风格中的这一行:
Key thing for me was this line in the activity style:
// Important to draw through the cutouts
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
我想以沉浸式模式显示图像,当我单击它时,系统UI(状态和导航栏)应该显示.
I wanted to show an image in immersive mode, and when I click it, the system UI (status & navigation bars) should show up.
这是我完整的解决方案:
Here is my complete solution:
1-在活动"中显示/隐藏系统UI的方法
1- Methods to show/hide system UI in the 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布局的根视图中
2- Make sure this in the root view of your xml layout
android:fitsSystemWindows="false"
3-全屏活动样式将在状态栏/导航栏显示时为其提供半透明的背景:
3- The Style for the Full screen Activity will give status/navigation bars a semi transparent background when they show up:
<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>
这篇关于如何删除顶部状态栏黑色背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!