【问题标题】:Need fully transparent status bar需要完全透明的状态栏
【发布时间】:2016-05-04 05:17:23
【问题描述】:

您好朋友,我想知道我可以更改状态栏颜色或使其完全透明。

我尝试了很多东西,但我无法获得完全透明的状态栏,所以这是我的代码..

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>

之后我的屏幕显示为...

我想要这样..

谁能帮忙?谢谢。

【问题讨论】:

    标签: android android-studio statusbar transparent


    【解决方案1】:

    我知道回答这个问题已经晚了,但这对我有帮助,并且可能对未来的访客有所帮助..

    // 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在这里指的是什么?根视图?
    • @fahmy 你得到它还是需要帮助?
    • 是的,请,仍然希望得到一些帮助。
    【解决方案2】:

    你不需要写所有这些东西,只需添加你的 kotlin 活动

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

    在你的主题中

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

    【讨论】:

      【解决方案3】:

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

      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
      

      【讨论】:

      • 我把这个十六进制代码放在哪里?因为我对十六进制代码一无所知。
      • 放在这里 @color/colorPrimary 放 #00ffffff 尝试另一个透明化
      • 谢谢@Damini Mehra
      • 我只是从我的 v21/style.exe true 中删除了这一行,然后尝试使用你的代码,它不能正常工作,谢谢很多
      猜你喜欢
      • 1970-01-01
      • 2020-04-15
      • 2022-08-09
      • 2021-02-26
      • 2016-10-27
      • 1970-01-01
      • 2023-03-29
      • 2022-11-28
      相关资源
      最近更新 更多