android - Lollipop 中工具栏的背景色是正常的,但 Kitkat 中是白色的

标签 android android-5.0-lollipop android-toolbar android-4.4-kitkat

在 Lollipop 中,toolbar 的背景色显示正常,但在 KitKat 中,显示为白色。 我不知道为什么。

activity_main.xml

<android.support.design.widget.CoordinatorLayout 
    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:fitsSystemWindows="true"
    tools:context=".MainActivity">

<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>

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

</android.support.design.widget.CoordinatorLayout>

样式.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" />
</resources>

styles.xml-v21

<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>
</resources>

enter image description here

最佳答案

尝试将 AppBarLayout 放在代码的末尾。显然,您包含的布局与工具栏重叠。那件事发生在我身上,我修复了它,它只是出现在我的脑海中。像这样:

<android.support.design.widget.CoordinatorLayout 
    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:fitsSystemWindows="true"
    tools:context=".MainActivity">

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

    <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 - Lollipop 中工具栏的背景色是正常的,但 Kitkat 中是白色的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35475344/

相关文章:

android - 在 web View 中将可绘制资源作为图像访问

android - 使用 android 4.2.2 破解 RTL 参数的错误行为

android - 如何通过 Intents 打开电子邮件程序(但仅限于电子邮件程序)

适用于手机和电视的 Android 通用应用程序 (Lollipop)

Android - 工具栏和状态栏作为内容更改的共享对象

android - 拒绝重新初始化 Android Lollipop 上先前失败的类 java.lang.Class<library.package.class>

Android 设计支持 TabLayout 重叠内容

java - 学习 Smali 的最佳方式是什么(以及如何/何时使用 Dalvik VM 操作码)?

android - 如何从 MenuItem 导航到 fragment (Android)?

android - 让抽屉导航滑到工具栏/操作栏下方