我想在android上创建半透明栏。这是我的样式代码和版本设置:
<resources>
<!-- Base application theme. -->
<style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="MyAppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyAppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" >
</style>
<style name="MyAppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
对于api级别上升21,我的风格如下:
<resources>
<style name="MyAppTheme.NoActionBar" parent="MyAppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
然后在我的清单中我有这些设置:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/MyAppTheme">
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/MyAppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
状态栏背景未设置为colorPrimaryDark,这绝对不是白色。为什么?
答案 0 :(得分:0)
您必须在主题中设置windowTranslucentStatus标志,而不是更改状态栏颜色。改变这个:
<item name="android:statusBarColor">@android:color/transparent</item>
对此:
<item name=”android:windowTranslucentStatus”>true</item>