How to make a transparent status bar in Android 4.4?

不打扰是莪最后的温柔 提交于 2019-12-12 03:44:05

问题


I want to make a transparent status bar in my application in Android 4.4. How do I do that?

I tired:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/skipPrimary</item>
        <item name="colorPrimaryDark">@color/skipPrimary</item>
        <item name="colorAccent">@color/skipPrimary</item>
    </style>

and in the manifest:

<application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme" >

and in the activity:

<activity
            android:name=".activities.StartActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme"
            android:windowSoftInputMode="adjustResize|stateHidden" />

回答1:


This one will throw exception on Lollipop devices. primColor must be opaque.

<item name="primColor">@android:color/transparent</item> 

Style your actionbar using style.xml

<style name="ThemeActionBar"
        parent="Widget.AppCompat.Light.ActionBar.Solid">
        <item name="android:background">@null</item>
        <!-- Support library compatibility -->
        <item name="background">@null</item>
</style>

Include you theme..

<item name="android:actionBarStyle">@style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/ThemeActionBar</item>
<item name="windowActionBarOverlay">true</item>



回答2:


What you can also do is set the status bar a darker shade of your background or even the same color by setting it in your activity.

You can set the status bar color in your activity with the following code getWindow().setStatusBarColor(getResources().getColor(R.color.your_color));.

If you want to use a darker shade of your color you can do it by changing your color's HSB. For a more detailed way of doing that you can read this post: Android change status bar color by converting existing color's HSB



来源:https://stackoverflow.com/questions/31716278/how-to-make-a-transparent-status-bar-in-android-4-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!