Fatih
Fatih

Reputation: 1354

Custom Colors are not recognized for Wear OS

I am developing a wear application in android studio. I defined my colors in

res->color->colors.xml ( Here is my folder structre)

When I open a new project for phone or tablet, colors.xml is placed in values folder by Android studio. But this time for wear project Android studio created new folder called color and placed the colors.xml automatically inside it.

The thing is I cannot use colors defined in colors.xml for wear project.

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>

When I'd like to use them in my activity_login.xml file none of the custom colors (colorPrimary,colorPrimaryDark etc..) are not recognized and android studio gives the following error.

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)}

So my question is how to get rid of this error and define custom colors when developing wear app?

EDIT

It is colors.xml not colors.mxl. I misspelled it.

Upvotes: 0

Views: 229

Answers (1)

Sterling
Sterling

Reputation: 6635

You've got a couple of mistakes visible. It's not clear how many are in your code and how many are just in your SO question, but fix these and I'll bet it'll work:

  1. You named the file colors.**mxl** at one point. Spelling matters!
  2. It needs to be in res\values, not res\color

Upvotes: 2

Related Questions