需要完全透明的状态栏

6

大家好,我想知道是否可以更改状态栏颜色或使其完全透明。

虽然我尝试了很多方法,但我无法获得完全透明的状态栏,这是我的代码:

v21/style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

        style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>

            <item name="android:windowTranslucentStatus">true</item>

            <item name="android:windowNoTitle">true</item>
            <item name="android:statusBarColor">@android:color/transparent</item>
            <item name="android:windowTranslucentNavigation">true</item>
        </style>
</resources>

以及style.xml

    <resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

    </style>
</resources>

在我使用之后,我的屏幕显示为... current login screen 我希望它变成这样... desired login screen 有人能帮忙吗?谢谢。
3个回答

14

我知道回答这个问题有点晚,但这是帮助了我并可能会帮助未来访问者的方法。

// transparent statusbar for marshmallow and above
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (yourView != null) {
            yourView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }

    //make full transparent statusBar
    if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
        setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, true);
    }
    if (Build.VERSION.SDK_INT >= 19) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
    if (Build.VERSION.SDK_INT >= 21) {
        setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, false);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }

 public static void setWindowFlag(Activity activity, final int bits, boolean on) {
    Window win = activity.getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    if (on) {
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
    }
    win.setAttributes(winParams);
}

你的 yourView 在这里指的是什么?RootView 吗? - fahmy
@fahmy你明白了还是需要帮助? - Kriti
是的,请帮我翻译这个。仍然需要一些帮助。 - fahmy

0

你不需要写所有这些东西,只需在你的 Kotlin 活动中添加即可

requestWindowFeature(Window.FEATURE_NO_TITLE)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)

并且在您的主题中

<item name="android:windowActivityTransitions">true</item>

-5

尝试使用这个十六进制代码透明度:

100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00

我应该把这个十六进制代码放在哪里?因为我对十六进制代码一无所知。 - Sourabh
把它放在这里 <item name="colorPrimary">@color/colorPrimary</item> 放上 #00ffffff 试试其他透明度 - Damini Mehra
感谢 @Damini Mehra - Sourabh
1
我刚刚从我的v21/style.exe中删除了这行代码 <item name="android:windowTranslucentStatus">true</item>,并尝试了你的代码。现在它可以工作了,之前不行。非常感谢。 - Sourabh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接