Reputation: 3918
I have a resource file containing colors which I reference from my layout file to set text color. The text is set to the assigned colors on my emulator, but the text is all set to black on my phone.
colors.xml
<resources>
<color name="myColor1">#eaf0a4</color>
<color name="myColor2">#1643a4</color>
</resources>
activity_myActivity.xml (layout)
<RelativeLayout
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:id="@+id/myActivityID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:background="@android:color/white" >
<View
android:background="@android:color/white"
android:clickable="true"
android:elevation="2dp"
android:id="@+id/whiteBackground"
android:layout_height="match_parent"
android:layout_width="match_parent" />
<TextView
android:id="@+id/text1"
android:elevation="4dp"
android:layout_marginTop="2dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_height="60dp"
android:layout_width="wrap_content"
android:text="Hello world!"
android:textAlignment="center"
android:textColor="@color/myColor1"
android:textSize="12sp" />
<Button
android:background="@android:color/white"
android:id="@+id/button1"
android:layout_below="@+id/myText1"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_width="wrap_content"
android:text="Click me!"
android:textAllCaps="false"
android:textColor="@color/myColor2"
android:textSize="10sp" />
</RelativeLayout>
Does anyone understand why text is set to the right colors on my emulator, but the text is all set to black on my phone?
Upvotes: 1
Views: 160
Reputation: 8237
It may be the reason that the background color is similar to the text color
android:layout_below="@+id/text1"
Try this . It's not clear in your code .
<RelativeLayout 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:id="@+id/myActivityID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:background="@android:color/white">
<View
android:id="@+id/whiteBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:clickable="true"
android:elevation="2dp" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginTop="2dp"
android:elevation="4dp"
android:gravity="center"
android:text="Hello world!"
android:textAlignment="center"
android:textColor="@color/myColor1"
android:textSize="12sp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text1"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:background="@android:color/white"
android:text="Click me!"
android:textAllCaps="false"
android:textColor="@color/myColor2"
android:textSize="10sp" />
</RelativeLayout>
OUTPUT
Upvotes: 1
Reputation: 2708
On your phone, Go to Settings > Accessibility and switch off the High Contrast Text. It will solve the issue.
Upvotes: 1