我有一个布局,用于根据 colorPrimaryDark
更新状态栏的背景颜色。
当布局的根布局是 CoordinatorLayout
时效果很好,但是当我将它切换到 LinearLayout
时,状态栏背景不再更新。
布局的来源和屏幕截图粘贴在下面。还列出了一个正常工作的布局示例。
谢谢!
布局.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".churches.ChurchesActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="@+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
样式.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" 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="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
样式-v21.xml
<resources>
<style name="AppTheme.NoActionBar">
<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>
状态栏不是 colorPrimaryDark
状态栏是 colorPrimaryDark
最佳答案
发布 styles-v21.xml 时,我发现 android:statusBarColor 设置为透明:
<item name="android:statusBarColor">@android:color/transparent</item>
将 android:statusBarColor 更改为 colorPrimaryDark 修复了它。谢谢!
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
不确定为什么在从 CoordinatorLayout 切换到 LinearLayout 后 statusBarColor 开始起作用。谢谢!
关于android - 如何获取状态栏背景颜色以显示colorPrimaryDark,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34279467/