在android studio的textview中设置文本颜色时出错

nkhmeac6  于 2021-07-11  发布在  Java
关注(0)|答案(2)|浏览(725)

我试图在androidstudio中设置文本视图的文本颜色,在androidstudio的预览中它看起来很好。。。但是,当在物理设备上运行时,它会显示完全不同的颜色。
这是xml文件中的文本视图

<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>

以下是它在android studio中的表现:

下面是它在我的设备上的显示方式(使用usb调试)

如何正确设置颜色?

yrwegjxp

yrwegjxp1#

可能的解决方案:
在不使用colors.xml的情况下尝试其他颜色(例子: android:textColor="#000000" )
在模拟器上试试。
File > Invalidate Caches / Restart . 它将清除缓存并重启androidstudio。
Build > Clean Project ,那么 Build > Rebuild Project .
你可以试试这些解决办法。

lsmepo6l

lsmepo6l2#

这取决于设备,请尝试使用其他设备或模拟器。这不是色码问题。

相关问题