背景选择器之代码实现

来源:互联网 发布:windows系统看图纸软件 编辑:程序博客网 时间:2024/05/17 01:05
        Drawable normal = null;        Drawable pressed = null;        Drawable focus = null;        StateListDrawable stateListDrawable = new StateListDrawable();        // 注意该处的顺序,只要有一个状态与之相配,背景就会被换掉        // 所以不要把大范围放在前面了,如果sd.addState(new[]{},normal)放在第一个的话,就没有什么效果了        stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, focus);        stateListDrawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed);        stateListDrawable.addState(new int[] { android.R.attr.state_focused }, focus);        stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressed);        stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, normal);        stateListDrawable.addState(new int[] {}, normal);

原创粉丝点击