Search code examples
javaandroidtextcolor

change android text color


I trying to change my text color by using below code.

 <TextView android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLefe="5dp"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/blue"/>

However the compiler said cannot resolve symbol @color/blue. I refer to http://android4beginners.com/2013/07/lesson-1-3-how-to-change-a-color-of-text-and-background-in-textview/ but why it's not working for me?

colors.xml

<?xml version="1.0" encoding="utf-8"?>  

    <resources>
        <color android:name="green">#00ff00</color>
        <color android:name="red">#FF0000</color>
        <color android:name="blue">#0000FF</color>
    </resources>

Edited

enter image description here

Mainfest.java

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

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="18" />
    <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity android:name =".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        </activity>
        <activity
            android:name=".WorkDetailsTable">
            </activity>
        <activity android:name=".WorkForce">
        </activity>

        <activity android:name=".ListDisplay">
            </activity>
        <activity android:name=".UpdatePage">
            </activity>

        <activity android:name=".UpdatePage2">
        </activity>

    </application>

</manifest>

How to fix this?


Solution

  • you have to create color.xml file in values folder like in he image below enter image description here

    and in the file write

     <?xml version="1.0" encoding="utf-8"?>
      <resources>
       <color name="blue">#0000FF</color>
     </resources>