[英]How to make the status bar completely transparent with dark text color with Kotlin
I use Kotlin to create an android app, I would like to know how to make the status bar completely transparent with dark text color with Kotlin I seen the following soltuion but not work for me Dark-text transparent status bar with opaque navigation bar Here's my following code :我使用 Kotlin 创建了一个 android 应用程序,我想知道如何使用 Kotlin 使状态栏完全透明并带有深色文本 我看到以下解决方案但对我不起作用带有不透明导航栏的深色文本透明状态栏这是我的以下代码:
if (VERSION.SDK_INT in 19..20) {
setWindowFlag(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, true)
}
if (VERSION.SDK_INT >= 19) {
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
if (VERSION.SDK_INT >= 21) {
setWindowFlag(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, false)
window.statusBarColor = Color.TRANSPARENT
}
Here's the custom style in style.xml:这是 style.xml 中的自定义样式:
<style name="MyStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowNoTitle">true</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:navigationBarColor">@android:color/black</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
And my xml code :还有我的 xml 代码:
<..... android:fitsSystemWindows="true" ....> <..... android:fitsSystemWindows="true" ....>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="189dp"
app:elevation="0dp"
android:theme="@style/MyStyle" ....>
I want to know where's the problem in my code and How can I correct it to get the status bar completely transparent with dark text color我想知道我的代码中的问题出在哪里,以及如何更正它以使状态栏完全透明并带有深色文本
You have to follow three steps.你必须遵循三个步骤。
Update your style.xml and main theme更新你的 style.xml 和主题
<item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item>
In your main xml add在您的主要 xml 添加
android:fitsSystemWindows="true"
In your activity before setcontView
add在
setcontView
添加之前的活动中
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.