【发布时间】:2021-03-01 16:44:21
【问题描述】:
我正在尝试在 Android Studio 中设置 TextView 的文本颜色,并且在 Android Studio 的预览中它看起来很好......但是,在物理设备上运行它时,它会显示完全不同的颜色。
这是 XML 文件中的 TextView
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="268dp"
android:text="Book S Mart is a place where \npeople can exchange used and new\nbooks of all types.\n\nEvery year millions of books\nare sent to recycling although they can be used again\n\nOur goal is to provide these books to those in need as well as Help the environment"
android:textAlignment="center"
android:textColor="@color/homeText"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
这是colors.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
<color name="homeText">#060E5A</color>
</resources>
这是它在我的设备上的显示方式(使用 USB 调试)
如何正确设置颜色?
【问题讨论】:
-
非常奇怪的行为...也许尝试在 Android Studio 中构建 -> 清理项目,然后安装调试版本
-
你能确认JAVA文件没有任何与Textcolor相关的代码吗?
-
Java 文件中没有与 TextColor 相关的代码...
-
在不同的物理设备上试试看
标签: java android text colors formatting