无法在android xml中设置文本视图的文本颜色

无法在android xml中设置文本视图的文本颜色,android,android-layout,android-studio,textview,Android,Android Layout,Android Studio,Textview,很抱歉问这个愚蠢的问题,但我无法在android xml中设置textcolor属性。 这是我的代码: <TextView android:layout_marginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Name"

很抱歉问这个愚蠢的问题,但我无法在android xml中设置textcolor属性。 这是我的代码:

  <TextView
            android:layout_marginTop="10dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name"
            android:textStyle="bold"
            android:textColor="@color/TextColor"
            android:textSize="35dp"
            android:layout_gravity="center_horizontal"/>

请帮助

如果您的Android Studio有大量缓存,有时可能会发生这种情况。所以试着清理缓存


转到
文件>使缓存无效/重新启动
单击它。也许能解决你的问题。

我也面临同样的问题。我认为这是设备特有的问题。我在nexus和motorola设备上进行了测试,它工作正常,但在MI设备中选择了设备默认颜色。要解决此问题,请通过编程设置文本颜色

TextView textView = (TextView) findViewById(R.id.yourid);
textView.setTextColor(ContextCompat.getColor(this,R.color.TextColor));

您可以使用编程方式

setTextColor(Color.parseColor("#00427E"));

尝试Textview xml代码
从您所写的内容来看,实现应该是有效的:

android:textColor="@color/TextColor"
是更改文本颜色的属性

我的建议是,检查放置此TextView的布局的背景色。背景颜色可能与您试图在TextView上设置的颜色相同,这就是您无法看到差异的原因

如果您想再次确认,请在TextView上设置黑色或白色,然后查看它是否按需要显示在屏幕上


如果仍然没有得到所需的结果,请将完整的xml粘贴到此处,以便我们更好地了解发生了什么

您使用的是哪种文本颜色?它应该是工作的,请在运行时检查相同的文本视图,某些地方将更改
name=“textColor”
,并在您的color.xml中将.chane textColor更改为textColor,并将其添加到您的xml文件中android:textColor=“@color/textColor”,而不是通过xml进行设置,您是否以编程方式尝试过?@Priyanka Minhas您是否检查过我的答案。?您的
color
位置在哪里?
res/values/color.xml
谢谢您的回答。我通过编程设置文本颜色解决了这个问题。我不知道,在xml中,运行时没有显示所需的颜色。虽然我也可以在布局中看到这些颜色。我通过添加白色和黑色进行检查,但没有use@PriyankaMinhas,我知道你现在一定已经厌倦了这件事,既然你已经用代码解决了它,你现在可能不想改变任何事情。但是,如果可能的话,请尝试一下最后一件事,而不是在color.xml中使用#00427E。我没有注意到这一点,可能就是这样。使用较小的T代替大写字母T。请试一下,告诉我们发生了什么。
setTextColor(Color.parseColor("#00427E"));
setTextColor(getResources().getColor(R.color.TextColor);
 <TextView
    android:layout_marginTop="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Name"
    android:textStyle="bold"
    android:textColor="#00427E"
    android:textSize="35sp"
    android:layout_gravity="center"/>
setTextColor(Color.parseColor("#00427E"));
android:textColor="@color/TextColor"