Wear 无法识别自定义颜色 OS

Custom Colors are not recognized for Wear OS

我正在 android studio 开发 wear 应用程序。我在

中定义了我的颜色

res->color->colors.xml ()

当我为 phone 或平板电脑打开一个新项目时,colors.xml 被 Android studio 放置在 values 文件夹中。但是这次为 wear project Android studio 创建了一个名为 color 的新文件夹,并自动将 colors.xml 放入其中。

问题是我不能将 colors.xml 中定义的颜色用于磨损项目。

colors.mxl

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<color android:name="colorPrimary">#006064</color>
<color android:name="colorPrimaryDark">#004c40</color>
<color android:name="colorAccent">#82b1ff</color>
<color android:name="black_alpha_40">#66000000</color>

</selector>

activity_login.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout
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:background="@color/dark_grey"
android:padding="@dimen/box_inset_layout_padding"
tools:context=".activities.LoginActivity"
tools:deviceIds="wear">


    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp"
        app:boxedEdges="all">
    <EditText
        android:id="@+id/loginEmailEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Email"
        android:inputType="textEmailAddress"
        android:layout_gravity="top"
        />

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="top"
            android:src="@drawable/logo"
            android:tint="@color/colorAccent" --->THERE IS AN ERROR HERE
            />
    </FrameLayout>

    <EditText
        android:id="@+id/loginPasswordEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Parola"
        android:inputType="textPassword"
        android:layout_gravity="center"/>

    <ImageButton
        android:id="@+id/loginButton"
        android:background="@drawable/circular_button"
        android:layout_height="50dp"
        android:layout_width="50dp"
        android:src="@drawable/done_white"
        android:text="Giriş"
        android:onClick="attemptLogin"
        android:layout_gravity="bottom|center"/>
</FrameLayout>
</android.support.wear.widget.BoxInsetLayout>

当我想在我的 activity_login.xml 文件中使用它们时 none 无法识别自定义颜色(colorPrimary、colorPrimaryDark 等..)并且 android studio 给出了以下错误。

error: resource color/colorAccent (aka com.muhendis.diabetwatch:color/colorAccent) not found. Message{kind=ERROR, text=error: resource color/colorAccent (aka com.muhendis.diabetwatch:color/colorAccent) not found., sources=[/Users/muhendis/Documents/AndroidStudioProjects/DiabetWatch/app/src/main/res/layout/activity_login.xml:32], original message=, tool name=Optional.of(AAPT)}

所以我的问题是如何在开发 wear 应用程序时摆脱这个错误并定义自定义颜色?

编辑

是colors.xml而不是colors.mxl。我拼错了。

你有几个明显的错误。目前尚不清楚您的代码中有多少以及您的 SO 问题中有多少,但修复这些问题我敢打赌它会起作用:

  1. 您曾将文件命名为 colors.**mxl**。拼写很重要!
  2. 它需要在 res\values,而不是 res\color