显示在模拟器上但不是电话上的文本颜色

问题描述:

我有一个资源文件,其中包含从我的布局文件中引用的用于设置文本颜色的颜色。文本在我的模拟器上设置为指定的颜色,但手机上的文本全部设置为黑色。显示在模拟器上但不是电话上的文本颜色

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> 

没有人明白为什么文本设置为我的模拟器正确的颜色,但文本在我的手机上全部设置为黑色?

在手机上,转到设置>辅助功能,然后关闭高对比度文本。它将解决问题。

+0

谢谢!这解决了我的问题。 – Rbar

+0

很高兴我能帮到你。 –

这可能是背景颜色相似的文本颜色

  • 变化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> 

输出

enter image description here