android - Wear OS 无法识别自定义颜色
问题描述
我正在android studio中开发一个磨损应用程序。我定义了我的颜色
当我为手机或平板电脑打开一个新项目时,colors.xml 被 Android Studio 放置在 values 文件夹中。但这一次,Android Studio 为 Wear 项目创建了一个名为 color 的新文件夹,并自动将 colors.xml 放入其中。
问题是我不能将 colors.xml 中定义的颜色用于磨损项目。
颜色.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>
活动登录.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 文件中使用它们时,没有一个自定义颜色(colorPrimary、colorPrimaryDark 等)无法识别,并且 android studio 给出了以下错误。
错误:找不到资源颜色/colorAccent(又名 com.muhendis.diabetwatch:color/colorAccent)。消息{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],原始消息=,工具名称=Optional.of(AAPT)}
所以我的问题是如何在开发穿戴应用程序时摆脱这个错误并定义自定义颜色?
编辑
它是colors.xml 不是colors.mxl。我拼错了。
解决方案
你有几个可见的错误。目前尚不清楚您的代码中有多少以及您的 SO 问题中有多少,但解决这些问题,我敢打赌它会起作用:
- 您曾一度命名该文件
colors.**mxl**
。拼写很重要! - 它需要在
res\values
,而不是res\color
推荐阅读
- ruby-on-rails - nil:NilClass 的未定义方法“create”
- python - 如何将长/纬度整数从谷歌历史 JSON 转换为谷歌地图格式?
- mule - Postman 不考虑以 # 开头的查询参数值
- three.js - ThreeJS - 如何在“mouseout”上缩小相交对象
- python - 在tkinter中单击按钮上的两个脚本之间的链接?
- laravel - Laravel - 如何从与数据透视表相关的表中获取数据
- c++ - 将用户输入的术语与 txt 文件中的列表进行比较
- google-chrome-extension - 如何重新加载后台脚本?
- c++ - 检查二维向量中是否存在元素
- c# - 如何确保使用泛型在工厂中实例化对象的设计时检查?