【发布时间】: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 deviceSettings > Accessibility并关闭High contrast text。 -
@Ironman 确实是
-
请参考这个网址可能对你有帮助。 stackoverflow.com/questions/39808968/…
-
大声哭泣。多么尴尬。您应该将其放在答案中,以便我可以将解决方案归功于您。我的高对比度文本选项被打开并杀死了我的文本颜色。谢谢。
标签: android xml android-layout textview textcolor