public static StateListDrawable makeSelector(Context context, int idNormal, int idPressed, int idFocused) { StateListDrawable bg = new StateListDrawable(); Drawable normal = context.getResources().getDrawable(idNormal); Drawable pressed = context.getResources().getDrawable(idPressed); Drawable focused = context.getResources().getDrawable(idFocused); bg.addState(new int[]{android.R.attr.state_pressed,}, pressed); bg.addState(new int[]{android.R.attr.state_focused}, focused); bg.addState(new int[]{}, normal); return bg;} 注意: 1.normal state要在最后add 2.要使用button测试
时间: 2024-12-22 03:24:04