错误的工具栏背景(Android)

3
我在我的应用中使用了工具栏,它应该像下面这样: enter image description here 但是,有时候工具栏的背景颜色会出现问题!我不知道为什么会发生这种情况...
这是我的布局:

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
<include layout="@layout/toolbar"/>
......

这是我的工具栏:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/id_toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"/>

帮帮忙!有什么想法吗?

设备:
Nexus 5(4.4.4)
华为荣耀6(4.4.2)


android:background="?attr/colorPrimary",请改用@color/colorPrimary。 - Rushi Ayyappa
1个回答

0

请检查您的样式资源文件是否定义了colorPrimary

非常重要的是要检查您的定义中是否有类似于这样的内容<item name="android:colorPrimary">@color/actionbar_solid_background</item>。这在Android(<21)的早期版本中不起作用,因为它针对操作系统的本地资源。如果是这种情况,请删除android:以针对支持库使用的资源。

您的样式应该像这样。

<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/actionbar_solid_background</item>
    <item name="colorPrimaryDark">@color/actionbar_solid_background</item>
</style>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接