AppCompatActivity 的 TextView 颜色始终为白色

Jis*_*ant 5 android android-appcompat android-studio android-styles

TextView在 Marshmallow 之前的设备上,a 的文本颜色始终为白色。即使我在 XML 中使用黄色或黑色,除了棉花糖之外,它始终是白色的。

在运行时,它将在所有设备上正常工作。以前,当我使用 Eclipse 时,一切正常,但在 Android Studio 中它没有从 XML 中获取属性。

我搜索过的所有问题都说要更改Theme.AppCompat为Theme.AppCompat.Light,但这除了将白色更改为黑色之外没有任何作用。我认为存在风格错误。这是我的样式代码:

 <style name="AppBaseTheme" parent="Theme.AppCompat">
        <item name="colorPrimary">@color/khaki</item>
        <item name="colorPrimaryDark">@color/khaki</item>
        <item name="colorAccent">@color/my_yellow</item>

        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>
Run Code Online (Sandbox Code Playgroud)

这是我的 xml

 <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="48dp">
   <ImageView
    android:id="@+id/icon1"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
     android:src="@drawable/sj_icon"
    android:layout_centerVertical="true"/>

   <TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:layout_alignLeft="@+id/icon1"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="32dp"
    android:gravity="center_vertical"
    android:minHeight="34dp"
    android:paddingLeft="7dp"
    android:text="hello"
    android:textColor="@color/my_yellow"
    android:textSize="18sp" />

   </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Jis*_*ant 1

我终于得到了问题的答案,实际上我正在使用最新版本的支持库,这导致了问题我将所有内容与我同事的项目进行了比较,因为他的应用程序运行良好..
使用这个

compile 'com.android.support:appcompat-v7:23.1.1'
Run Code Online (Sandbox Code Playgroud)

工作室将给弹出窗口一个更新的版本也可用,但不要使用它,因为 24 版本处于 alpha 阶段。