私はAndroidStudioでウェアアプリケーションを開発しています。私は自分の色をで定義しました
携帯電話またはタブレット用の新しいプロジェクトを開くと、colors.xmlはAndroidStudioによってvaluesフォルダーに配置されます。ただし、今回のウェアプロジェクトでは、Android Studioがcolorという新しいフォルダーを作成し、その中にcolors.xmlを自動的に配置しました。
事は私がwearプロジェクトのために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>
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など)が認識されず、androidstudioで次のエラーが発生します。
エラー:リソースcolor / 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.mxlではなくcolors.xmlです。スペルを間違えました。
いくつかの間違いがあります。コードに含まれている数とSOの質問に含まれている数は明確ではありませんが、これらを修正すれば、うまくいくと思います。
colors.**mxl**
ある時点でファイルに名前を付けました。スペルが重要です!res\values
ではなく、res\color
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加