【发布时间】:2018-06-10 15:48:28
【问题描述】:
我正在 android studio 中开发一个磨损应用程序。我在
中定义了我的颜色当我为手机或平板电脑打开一个新项目时,colors.xml 被 Android Studio 放置在 values 文件夹中。但这一次,Android Studio 为 Wear 项目创建了一个名为 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 文件中使用它们时,没有任何自定义颜色(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], original message=, tool name=Optional.of(AAPT)}
所以我的问题是如何在开发穿戴应用程序时摆脱这个错误并定义自定义颜色?
编辑
它是colors.xml 不是colors.mxl。我拼错了。
【问题讨论】:
标签: android android-layout wear-os android-resources android-color