当我尝试升级我的应用程序以使用 compileSdkVersion
23 进行编译时遇到了这个问题
正如我的标题所说,使用 android:textColor="@android:color/white"
的 TextView 不再有效。
我试图通过创建一个简单的测试应用程序来缩小原因,我发现每当我的 TextView 有 android:enabled="false"
时,我的 android:textColor
被忽略。
我想我要向 Android Developer Preview 提交问题,但是,我想确认这是否是我自己的问题。
这是我用来测试的TextView
<TextView
android:enabled="false"
android:textColor="@android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:textSize="50sp"
android:gravity="center"
android:layout_centerInParent="true"/>
编辑:
我在 github 上创建了一个非常简单的项目来解决这个问题,我已经在安卓 19、21、22、33 的模拟器上以及我的安卓 5.0 的 Moto G 上测试了它
最佳答案
作为解决方法,尝试使用具有已定义状态的选择器 android:state_enabled="false"。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/white" android:state_enabled="false"/>
<item android:color="@android:color/white"/>
</selector>
关于Android M 开发者预览版 - TextView android :textColor being ignored,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32394723/