颜色在android studio中是私有的吗?

时间:2018-09-11 12:29:37

标签: android xml android-studio android-studio-3.0

我在编译时始终收到此错误消息:

错误:资源android:color / foreground_material_dark是私有的。

我在这段代码中使用了这种材料

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/activity_main"
    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"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:background="@drawable/newbackground">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/rollButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="@color/colorPrimary"
            android:text="@string/button_text"
            android:textColor="@android:color/foreground_material_dark"/>
    </RelativeLayout>

</LinearLayout>

为什么会出现此错误?

2 个答案:

答案 0 :(得分:0)

在这种情况下,您应该使“自定义颜色”类似于此color.xml

<color name="mycolor">#0288D1</color>

然后使用它

<Button
        android:id="@+id/rollButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@color/colorPrimary"
        android:text="@string/button_text"
        android:textColor="@color/mycolor"/>

答案 1 :(得分:0)

在使用颜色的小部件上使用 tools:ignore =“ PrivateResource”

相关问题