Button不可用时颜色为灰色

时间:2022-08-26 12:41:59

需求描述:
当Button按钮不可用时,按钮颜色变灰。
代码:

<?xml version="1.0" encoding="utf-8"?>   
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/point_shape_click"/>
<item android:state_pressed="false" android:drawable="@drawable/point_shape" />
<item android:state_pressed="true" android:drawable="@drawable/point_shape_click" />
<item android:state_enabled="true" android:drawable="@drawable/point_shape"/>
<item android:state_focused="true" android:drawable="@drawable/point_shape_click" />
</selector>

其中android:state_enabled=”false”一定要写在最前面,否则得不到现象。