简体   繁体   中英

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

在此处输入图片说明

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?

you have to create color.xml file in values folder like in he image below在此处输入图片说明

and in the file write

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

You need to define blue hex color in values directory in colors.xml file Example of colors.xml file with blue color

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

</resources>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM