"无法将?attr/colorPrimary转换为drawable"

Ted*_*Ted 5 android material-design

我正在开始一个新项目,所以项目或多或少"空".我刚刚添加了MainActivity,带有MainActivtyFragment.我没有向他们添加任何代码.

现在,我编辑styles.xml,看起来像这样:

<resources>
    <!-- Base application theme. -->
    <style name="MyTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
        <item name="android:windowNoTitle">true</item>
        <!--We will be using the toolbar so no need to show ActionBar-->
        <item name="android:windowActionBar">false</item>
        <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
        <!-- colorPrimary is used for the default action bar background -->
        <item name="android:colorPrimary">#2196F3</item>
        <!-- colorPrimaryDark is used for the status bar -->
        <item name="android:colorPrimaryDark">#1976D2</item>
        <!-- colorAccent is used as the default value for colorControlActivated
             which is used to tint widgets -->
        <item name="android:colorAccent">#FF4081</item>
        <!-- You can also set colorControlNormal, colorControlActivated
             colorControlHighlight and colorSwitchThumbNormal. -->
        <item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

所以,我可以看到你扩展Material主题.

然后我创建一个工具栏xml文件(mytoolbar.xml),如下所示:

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/abc_ic_voice_search_api_mtrl_alpha"/>
</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)

这是问题所在:

在此输入图像描述

我无法弄清楚为什么.我已经完成了gradle sync,clean,rebuild,restarted IDE(Android Studio 1.2.1.1),没有任何效果.

有任何想法吗?

Abh*_*hek 1

android [pre-lollipop] 操作系统中存在一个错误,不允许您在可绘制对象中使用 attr。这是错误的链接:

https://code.google.com/p/android/issues/detail?id=26251

Android 开发团队已发布修复程序,但适用于 Android L 及更高版本。有关此问题的解决方法,请参阅以下解决方案:

如何从可绘制对象中引用样式属性?