android的selector代码化
android中使用selector可设置控件不同状态的表现,现在想些一个控件,直接在代码中完成selector的功能。部分代码如下:bg.addState(View.PRESSED_ENABLED_STATE_SET, pressed);//设置按下的背景
bg.addState(View.ENABLED_FOCUSED_STATE_SET, selected);//设置取得焦点的背景
问题来了:在setState的参数中没有找到disable时的状态,郁闷啊,只有enable!导致在代码中不能定义disable状态下的背景风格。
那位大侠知道如何在代码中设置disable状态??? --------------------编程问答-------------------- http://stackoverflow.com/questions/5092649/android-how-to-update-the-selectorstatelistdrawable-programmatically
You need to use the negative value of the needed state. E.g.:
states.addState(new int[] {-android.R.attr.state_enabled},R.drawable.btn_disabled);
Notice the "-" sign before android.R.attr.state_enabled.
补充:移动开发 , Android