简体   繁体   English

如何使用 Kotlin 使状态栏以深色文本颜色完全透明

[英]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.你必须遵循三个步骤。

  1. Update your style.xml and main theme更新你的 style.xml 和主题

    <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item>
  2. In your main xml add在您的主要 xml 添加

    android:fitsSystemWindows="true"
  3. In your activity before setcontView addsetcontView添加之前的活动中

    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.

相关问题 如何制作完全透明的状态栏? - How to make completely transparent status bar? 如何使状态栏透明和文本颜色为灰色? - How to make the status bar transparent and the text color is grey? 带有不透明导航栏的暗文本透明状态栏 - Dark-text transparent status bar with opaque navigation bar Android Full Height DialogFragment with transparent status bar color 如何更改状态栏文本颜色? - Android Full Height DialogFragment with transparent status bar color how to change status bar text color? 如何制作透明状态栏 - How to make transparent status bar 如何将Android L的状态栏颜色设置为完全透明? (无灰色) - How can I set the status bar color for Android L to be completely transparent? (No gray tint) Android 完全透明状态栏? - Android Completely transparent Status Bar? 是否可以将状态栏图标颜色更改为白色? 还是有深色主题状态栏? (科特林) - Is it possible to change status bar icon color to white? Or is there a dark theme status bar? (Kotlin) Ionic 3 Android 应用程序的状态栏文本颜色为深色或黑色 - Ionic 3 Android app's status bar Text color to Dark or Black "棒棒糖上完全透明的状态栏和导航栏" - completely transparent status bar and navigation bar on lollipop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM