按钮状态--代码设定
[java]采用xml写出来的效果皆可以用代码来实现,下面的代码就是通过代码编写来实现view的状态的切换效果。采用xml写出来的效果皆可以用代码来实现,下面的代码就是通过代码编写来实现view的状态的切换效果。[java] public void setPressedBg(View view, Drawable normal,Drawable focused, Drawable pressed) {
StateListDrawable bg = new StateListDrawable();
int[][] states = new int[6][];
states[0] = new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled };
states[1] = new int[] { android.R.attr.state_enabled, android.R.attr.state_focused };
states[2] = new int[] { android.R.attr.state_enabled };
states[3] = new int[] { android.R.attr.state_focused ,android.R.attr.state_window_focused};
states[4] = new int[] { android.R.attr.state_window_focused };
bg.addState(states[0], pressed);
bg.addState(states[3], focused);
bg.addState(states[2], normal);
view.setBackgroundDrawable(bg);
}
摘自 agods--足迹
补充:移动开发 , Android ,