thecoderenroute
thecoderenroute

Reputation: 43

Error setting color for Text in TextView in Android Studio

I am trying to set the Text Color of a TextView in Android Studio and in the preview in Android Studio it appears fine... However, When running it on a physical device, it shows a completely different color.

This is the TextView in the XML file

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="268dp"
    android:text="Book S Mart is a place where \npeople can exchange used and new\nbooks of all types.\n\nEvery year millions of books\nare sent to recycling although they can be used again\n\nOur goal is to provide these books to those in need as well as Help the environment"
    android:textAlignment="center"
    android:textColor="@color/homeText"
    android:textSize="22sp"
    android:textStyle="bold"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

and this is the colors.xml file

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#6200EE</color>
    <color name="colorPrimaryDark">#3700B3</color>
    <color name="colorAccent">#03DAC5</color>
    <color name="homeText">#060E5A</color>
</resources>

Here's how it appears in Android Studio:
On Android Studio

and here's how it appears on my device (Using USB debugging)

On My Mobile Phone Redmi K20 Pro

How do I set the Color properly?

Upvotes: 2

Views: 577

Answers (2)

Priyanka
Priyanka

Reputation: 1875

It depends upon device, Try with another device or emulator. This is not color code issue.

Upvotes: 0

harundemir918
harundemir918

Reputation: 432

Possible solutions:

  1. Try a different color without using colors.xml. (Example: android:textColor="#000000")

  2. Try it on an emulator.

  3. Go to File > Invalidate Caches / Restart. It will clear caches and restart Android Studio.

  4. Go to Build > Clean Project, then Build > Rebuild Project.

You can try these solutions.

Upvotes: 1

Related Questions