选择器禁用botton(selector disable botton)
我有一个选择器用于我的按钮背景之一
<?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/bg_botton_disable"/> <item android:state_pressed="true" android:state_enabled="true" android:drawable="@drawable/bg_botton_pressed"/> <!-- pressed --> <item android:state_enabled="true" android:drawable="@drawable/bg_botton" /> <!-- default --> </selector>(Button) bt = (Button) findviewById(R.id.MyBotton); bt.setEnabled(false);代码禁用了我的按钮的功能。 我的意思是当我按下按钮时它不会启动它自己的onClick()方法。 这很好,但问题是它不会将按钮的背景更改为bg_botton_disable drawable。
有没有人有任何建议如何解决它?
I have this selector for one of my button's background
<?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/bg_botton_disable"/> <item android:state_pressed="true" android:state_enabled="true" android:drawable="@drawable/bg_botton_pressed"/> <!-- pressed --> <item android:state_enabled="true" android:drawable="@drawable/bg_botton" /> <!-- default --> </selector>(Button) bt = (Button) findviewById(R.id.MyBotton); bt.setEnabled(false);The code disables the functionality of my button. I mean when I press the button it doesn't launch its own onClick() method. That's fine, but the problem is that it doesn't change the background of the button to bg_botton_disable drawable.
Does anyone has any suggestion how to fix it?
最满意答案
重新排序选择器项目
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:drawable="@drawable/bg_botton" /> <!-- default --> <item android:state_pressed="true" android:drawable="@drawable/bg_botton_pressed"/> <!-- pressed --> <item android:state_enabled="false" android:drawable="@drawable/bg_botton_disable"/> </selector>Reorder your selector items
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:drawable="@drawable/bg_botton" /> <!-- default --> <item android:state_pressed="true" android:drawable="@drawable/bg_botton_pressed"/> <!-- pressed --> <item android:state_enabled="false" android:drawable="@drawable/bg_botton_disable"/> </selector>
更多推荐
drawable,按钮,android,电脑培训,计算机培训,IT培训"/> <meta name="descripti
发布评论