我无法在 6.0 以下的任何版本 android 中设置 TextView 颜色

I can't set TextView color in any version of android under 6.0

我正在使用 android 支持库。在我的 XML 中,如果我使用 TextView,除了 android 6.0 之外,文本颜色在 android 的任何版本中都不会改变。我在多屏幕布局上遇到问题。

    <TextView
        android:id="@+id/tvStatus"
        android:textColor="#FFFFFF00"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:text="@string/ted240" />

如果我使用 android.widget.TextView,在旧版本 android 上一切正常。

    <android.widget.TextView
        android:id="@+id/tvStatus"
        android:textColor="#FFFFFF00"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:text="@string/ted240" />

我最近更新了支持库和 gradle。我不确定这是否导致了问题。如果我尝试将它们改回原样,我仍然会遇到同样的问题。

只能使用以下六位十六进制数,不能使用 8

  <TextView

       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textColor="#ff0000"
   />

从 Android 支持库 23 开始,新的 getColor() 方法已添加到 ContextCompat。

但是你可以像下面我使用的方法一样使用它,

public static int getColorWrapper(Context context, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getColor(id);
    } else {
        //noinspection deprecation
        return context.getResources().getColor(id);
    }
}

然后你需要像下面这样调用,

 textView.setTextColor(getColorWrapper(context,R.color.black));

希望这对你有用。

我尝试清理然后重建项目,但似乎无法修复它。我试着把它一直改回 'com.android.support:appcompat-v7:22'.

我似乎已经通过更改为

来修复它
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'

然后一旦它再次开始工作,我就改为

compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'

一切似乎都很好。我很困惑,但很高兴它有效。