我在我的Android应用程序中使用 TextView
作为 Button
(平面UI) . 下面是代码
<TextView
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/button_background"
android:enabled="false"
android:gravity="center"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:text="Sign Up"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold" />
背景drawable'button_background'是
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#FCD5A5" android:state_enabled="false" />
<item android:drawable="#F7941E" />
因此,当 Button
为 enabled 时,它应该具有 dark orange background ,否则为浅橙色背景 .
两种状态(启用和禁用)背景颜色都正常工作 but text color is also getting changed . 它在启用状态下保持白色,但在禁用状态下更改为深灰色 . 我想在两个州保持白色 .
2 回答
我目前正在研究如何为您的选择器执行此操作 . 但是现在,您可以始终执行此操作并将其调用一次以进行初始化,然后在状态更改时调用:
textcolorselector.xml <=将此文件放在drawable中
将此行添加到color.xml文件中
最后将其应用于您的布局