如何为“state_pressed”定义
Android按钮图像?
Java中的“android:state_focused”
Java中的“android:state_focused”
例如,如何从Java中获取Java中的等价物
http://developer.android.com/reference/android/widget/ImageButton.html
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/button_pressed" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/button_focused" /> <!-- focused --> <item android:drawable="@drawable/button_normal" /> <!-- default --> </selector>
解决方法
只需使用StateListDrawable的addState方法
StateListDrawable stateListDrawable = new StateListDrawable(); stateListDrawable.addState(new int[] {android.R.attr.state_pressed},getResources().getDrawable(R.drawable.phone));
android.R.attr.state_accelerated android.R.attr.state_activated android.R.attr.state_active android.R.attr.state_drag_can_accept android.R.attr.state_drag_hovered android.R.attr.state_enabled android.R.attr.state_first android.R.attr.state_focused android.R.attr.state_hovered android.R.attr.state_last android.R.attr.state_middle android.R.attr.state_pressed android.R.attr.state_selected android.R.attr.state_single android.R.attr.state_window_focused