透明状态栏未正确着色
Transparent statusbar is not tinted properly
我对 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>
但是 activity 不能正常使用它,就像这样:
如您所见,状态栏没有着色,只是变成蓝色,就像背景一样。我应该怎么做才能让它变色?
您不应同时使用 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>
我对 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>
但是 activity 不能正常使用它,就像这样:
如您所见,状态栏没有着色,只是变成蓝色,就像背景一样。我应该怎么做才能让它变色?
您不应同时使用 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>