【问题标题】:Transparent statusbar is not tinted properly透明状态栏未正确着色
【发布时间】:2015-10-22 11:26:21
【问题描述】:
我的 StatusBar 有问题,我设法为它实现了如下样式:
<resources>
<style name="AppTheme1" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">#59000000</item>
<item name="android:statusBarColor">#59000000</item>
<item name="colorAccent">@color/blueAppBar</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
但是活动不能正常工作,像这样:
如您所见,状态栏没有着色,只是蓝色,就像背景一样。我应该怎么做才能让它着色?
【问题讨论】:
标签:
android
android-statusbar
【解决方案1】:
您不应同时使用android:windowTranslucentStatus 和android:statusBarColor。
您应该在values-v19 中使用android:windowTranslucentStatus,在values-v21 中使用android:statusBarColor。
这是一个示例配置:
values/styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">#59000000</item>
<item name="colorAccent">@color/blueAppBar</item>
</style>
<style name="AppTheme.NoActionBar">
</style>
</resources>
values-v19/styles.xml
<resources>
<style name="AppTheme.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
values-v21/styles.xml
<resources>
<style name="AppTheme.NoActionBar">
<item name="android:statusBarColor">#59000000</item>
</style>
</resources>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>