Android TextView 的 textColor 仅在物理设备上错误
Android TextView's textColor is wrong only on Physical Device
对于 class,我正在尝试在 Android Studio 2.2 中制作一个基本的贺卡应用程序,build #AI-145.3276617,使用JRE: 1.8.0_76-release-b03.
"card" 在 RelativeLayout 中包含大图像和少量 TextView。
我试图在 Nexus 5 API24 模拟器 和 物理 Nexus 5 上进行测试 android 6.0 .1.
当我在模拟器上测试应用程序时,文本颜色显示正确,但是当我在我的物理设备上 运行 时,文本颜色显示错误。
设计视图和模拟器似乎都对文本感到满意:
但是我的物理设备的这个屏幕截图有不同的文字颜色:
我包含的 xml 显示我试图直接使用十六进制 textColor 值,但我也尝试将它们作为资源放置,结果相同。
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#2196F3</color>
<color name="colorPrimaryDark">#1976D2</color>
<color name="colorPrimaryLight">#BBDEFB</color>
<color name="colorAccent">#FFEB3B</color>
<color name="colorText1">#2196F3</color>
<color name="colorText2">#1976D2</color>
</resources>
我的activity_main.xml文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
tools:context="com.touchspin.hnspd.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/background" />
<TextView
android:id="@+id/happy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Happy"
android:textSize="72sp"
android:layout_marginTop="100dp"
android:textColor="#1976D2" />
<TextView
android:id="@+id/national"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="National"
android:textSize="40sp"
android:layout_below="@id/happy"
android:textColor="#2196F3" />
<TextView
android:id="@+id/sock_puppet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Sock Puppet"
android:textSize="24sp"
android:layout_below="@id/national"
android:textColor="#1976D2" />
<TextView
android:id="@+id/day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Day!"
android:textSize="24sp"
android:layout_below="@id/sock_puppet"
android:textColor="#2196F3" />
</RelativeLayout>
我已经尝试清理构建并重新启动 Android Studio、资源颜色和硬编码十六进制。如果能指出正确的方向,我将不胜感激。
对于LolliPop
设备或LolliPop
上层设备。如果 TextColor
显示不佳,您已禁用 High contrast Text
。默认情况下启用。
所以要解决问题转到 Settings > Accessibility
并关闭 High Contrast Text
。它会解决问题。
对于 class,我正在尝试在 Android Studio 2.2 中制作一个基本的贺卡应用程序,build #AI-145.3276617,使用JRE: 1.8.0_76-release-b03.
"card" 在 RelativeLayout 中包含大图像和少量 TextView。
我试图在 Nexus 5 API24 模拟器 和 物理 Nexus 5 上进行测试 android 6.0 .1.
当我在模拟器上测试应用程序时,文本颜色显示正确,但是当我在我的物理设备上 运行 时,文本颜色显示错误。
设计视图和模拟器似乎都对文本感到满意:
但是我的物理设备的这个屏幕截图有不同的文字颜色:
我包含的 xml 显示我试图直接使用十六进制 textColor 值,但我也尝试将它们作为资源放置,结果相同。
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#2196F3</color>
<color name="colorPrimaryDark">#1976D2</color>
<color name="colorPrimaryLight">#BBDEFB</color>
<color name="colorAccent">#FFEB3B</color>
<color name="colorText1">#2196F3</color>
<color name="colorText2">#1976D2</color>
</resources>
我的activity_main.xml文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
tools:context="com.touchspin.hnspd.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/background" />
<TextView
android:id="@+id/happy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Happy"
android:textSize="72sp"
android:layout_marginTop="100dp"
android:textColor="#1976D2" />
<TextView
android:id="@+id/national"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="National"
android:textSize="40sp"
android:layout_below="@id/happy"
android:textColor="#2196F3" />
<TextView
android:id="@+id/sock_puppet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Sock Puppet"
android:textSize="24sp"
android:layout_below="@id/national"
android:textColor="#1976D2" />
<TextView
android:id="@+id/day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Day!"
android:textSize="24sp"
android:layout_below="@id/sock_puppet"
android:textColor="#2196F3" />
</RelativeLayout>
我已经尝试清理构建并重新启动 Android Studio、资源颜色和硬编码十六进制。如果能指出正确的方向,我将不胜感激。
对于LolliPop
设备或LolliPop
上层设备。如果 TextColor
显示不佳,您已禁用 High contrast Text
。默认情况下启用。
所以要解决问题转到 Settings > Accessibility
并关闭 High Contrast Text
。它会解决问题。