【问题标题】:Android TextView's textColor is wrong only on Physical DeviceAndroid TextView 文本颜色仅在物理设备上错误
【发布时间】:2016-10-06 05:00:18
【问题描述】:

对于一个类,我正在尝试在 Android Studio 2.2 中制作一个基本的贺卡应用程序,build #AI-145.3276617,使用 JRE: 1.8.0_76-release-b03.

“卡片”在 RelativeLayout 中包含大图像和少量 TextView。

我已尝试在 Aandroid 6.0.1 上的 Nexus 5 API24 模拟器物理 Nexus 5 上进行测试。

当我在模拟器上测试应用程序时,文本颜色显示正确,但当我在物理设备上运行时,文本颜色错误。

设计视图和模拟器似乎都对文本感到满意:

但是我的物理设备的这个屏幕截图有不同的文本颜色:

我包含的 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、资源颜色和硬编码十六进制。如果您指出正确的方向,我将不胜感激。

【问题讨论】:

  • 转到您的Physical device Settings &gt; Accessibility 并关闭High contrast text
  • @Ironman 确实是
  • 请参考这个网址可能对你有帮助。 stackoverflow.com/questions/39808968/…
  • 大声哭泣。多么尴尬。您应该将其放在答案中,以便我可以将解决方案归功于您。我的高对比度文本选项被打开并杀死了我的文本颜色。谢谢。

标签: android xml android-layout textview textcolor


【解决方案1】:

对于LolliPop 设备或LolliPop 上位设备。如果TextColor 不能很好地显示,您已禁用High contrast Text。默认启用。

所以要解决问题转到Settings &gt; Accessibility 并关闭High Contrast Text。它会解决问题。

【讨论】:

  • 多年后仍然是一个非常有效的提示!在单个旧设备上的 React Native 中搜索这个“错误”太久了,尝试了一切,从调试器到原生 Java 项目。这只是一个容易错过的可访问性选项。谢谢@Ironman!
  • 除了禁用高对比度文本还有其他解决方案吗?
猜你喜欢
  • 2012-09-13
  • 1970-01-01
  • 2021-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多