(colorPrimaryDark)状态栏颜色不适用于android v21?

前端之家收集整理的这篇文章主要介绍了(colorPrimaryDark)状态栏颜色不适用于android v21?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在style.xml上添加了colorPrimaryDark,但状态栏 android v21上没有颜色受到影响.

我有一个自定义工具栏,我在style.xml代码中没有使用操作栏主题

如有任何解决方案请帮帮我?

样式代码: –

  1. <style name="AppTheme" parent="AppTheme.Base">
  2. <!-- Customize your theme here. -->
  3. </style>
  4.  
  5. <style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
  6. <item name="colorPrimary">@color/colorPrimary</item>
  7. <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  8. <item name="colorAccent">@color/colorAccent</item>
  9. </style>
  10.  
  11. <style name="myCustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
  12. <item name="android:textColorSecondary">@color/colorAccent</item>
  13. </style>

风格v21: –

  1. <style name="AppTheme" parent="AppTheme.Base">
  2. <item name="android:colorPrimary">@color/colorPrimary</item>
  3. <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
  4. <item name="android:colorAccent">@color/colorAccent</item>
  5.  
  6. <item name="windowActionBar">true</item>
  7. <item name="windowNoTitle">true</item>
  8. <item name="android:windowDrawsSystemBarBackgrounds">true</item>
  9. <item name="android:statusBarColor">@android:color/transparent</item>
  10. </style>

工具栏代码: –

  1. <android.support.v7.widget.Toolbar
  2. android:id="@+id/toolbar"
  3. android:layout_width="match_parent"
  4. android:layout_height="56dp"
  5. android:elevation="4dp"
  6. android:background="@color/colorPrimary"
  7. android:popupTheme="@style/Base.ThemeOverlay.AppCompat.Light"
  8. xmlns:android="http://schemas.android.com/apk/res/android" />

主要布局代码

  1. <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. tools:context=".MainActivity">
  6.  
  7. <LinearLayout
  8. android:fitsSystemWindows="true"
  9. android:layout_height="match_parent"
  10. android:layout_width="match_parent"
  11. android:orientation="vertical">
  12.  
  13. <include layout="@layout/custom_toolbar"/>
  14.  
  15. <Button
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:text="New Button"
  19. android:id="@+id/button1" />
  20.  
  21. </LinearLayout>
  22.  
  23.  
  24. <android.support.design.widget.FloatingActionButton
  25. xmlns:fab="http://schemas.android.com/apk/res-auto"
  26. android:layout_width="wrap_content"
  27. android:layout_height="wrap_content"
  28. android:id="@+id/fab"
  29. android:layout_gravity="right|bottom"
  30. android:src="@mipmap/ic_plus"
  31. android:onClick="fabClick"
  32. android:layout_marginRight="@dimen/fab_margin"
  33. android:layout_marginBottom="@dimen/fab_margin_bottom"
  34. fab:borderWidth="0dp"/>

解决方法

我认为您的CoordinatorLayout缺少以下属性:android:fitsSystemWindows =“true”
  1. <android.support.design.widget.CoordinatorLayout
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. tools:context=".MainActivity"
  7. android:fitsSystemWindows="true">

猜你在找的Android相关文章