(colorPrimaryDark)状态栏颜色在android v21上不起作用? [英] (colorPrimaryDark) status bar color not working on android v21?

查看:69
本文介绍了(colorPrimaryDark)状态栏颜色在android v21上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在style.xml上添加了colorPrimaryDark,但在状态栏android v21上没有影响颜色.

I have added colorPrimaryDark on style.xml but no color affected on status bar android v21.

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

i have a custom toolbar where i use no action bar theme in style.xml code

如果有解决方案,请帮助我吗?

if any solution please help me ?

样式代码:-

 <style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->
</style>

<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="myCustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:textColorSecondary">@color/colorAccent</item>
</style>

样式v21:-

  <style name="AppTheme" parent="AppTheme.Base">
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:colorAccent">@color/colorAccent</item>

    <item name="windowActionBar">true</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

工具栏代码:-

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

主布局代码

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
    android:fitsSystemWindows="true"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical">

    <include layout="@layout/custom_toolbar"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button1" />

</LinearLayout>


<android.support.design.widget.FloatingActionButton
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/fab"
    android:layout_gravity="right|bottom"
    android:src="@mipmap/ic_plus"
    android:onClick="fabClick"
    android:layout_marginRight="@dimen/fab_margin"
    android:layout_marginBottom="@dimen/fab_margin_bottom"
    fab:borderWidth="0dp"/>

推荐答案

我认为您的CoordinatorLayout缺少以下属性: android:fitsSystemWindows ="true"

I think your CoordinatorLayout is missing the following attribute: android:fitsSystemWindows="true"

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:fitsSystemWindows="true">

这篇关于(colorPrimaryDark)状态栏颜色在android v21上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆