模拟器上显示的文本颜色但未显示 phone

Text colors showing on emulator but not phone

我有一个包含颜色的资源文件,我从布局文件中引用这些颜色来设置文本颜色。文本在我的模拟器上设置为指定的颜色,但在我的 phone.

上文本全部设置为黑色

colors.xml

<resources>
    <color name="myColor1">#eaf0a4</color>
    <color name="myColor2">#1643a4</color>
</resources>

activity_myActivity.xml(布局)

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

有谁知道为什么在我的模拟器上文本设置为正确的颜色,但在我的 phone 上文本全部设置为黑色?

在您的 phone 上,转到“设置”>“辅助功能”并关闭“高对比度文本”。它将解决问题。

It may be the reason that the background color is similar to the text color

  • 改变android:layout_below="@+id/text1"

试试这个。您的代码中不清楚。

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

输出