daz*_*000 12 android android-layout android-linearlayout android-notification-bar android-coordinatorlayout
我有一个布局,用于更新状态栏的背景颜色colorPrimaryDark.
当布局的根布局为a时CoordinatorLayout,这很有用,但当我将其切换到LinearLayout状态栏时,背景不再更新.
布局源和屏幕截图粘贴在下面.还列出了正常工作的布局示例.
谢谢!
layout.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>
Run Code Online (Sandbox Code Playgroud)
styles.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" />
Run Code Online (Sandbox Code Playgroud)
款式 - 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>
Run Code Online (Sandbox Code Playgroud)
状态栏不是colorPrimaryDark
状态栏是colorPrimaryDark
daz*_*000 17
发布styles-v21.xml时发现android:statusBarColor设置为透明:
<item name="android:statusBarColor">@android:color/transparent</item>
Run Code Online (Sandbox Code Playgroud)
将android:statusBarColor更改为colorPrimaryDark修复它.谢谢!
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
Run Code Online (Sandbox Code Playgroud)
从CoordinatorLayout切换到LinearLayout后,不确定为什么statusBarColor开始起作用.谢谢!