问题
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