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);
背景選擇器之代碼實現
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.