通過程式碼改變drawable 各種狀態drawable
阿新 • • 發佈:2019-02-16
<span style="font-size:24px;">use StateListDrawable for seeting selector by code as: StateListDrawable states = new StateListDrawable(); states.addState(new int[] {android.R.attr.state_pressed}, getResources().getDrawable(R.drawable.pressed)); states.addState(new int[] {android.R.attr.state_focused}, getResources().getDrawable(R.drawable.focused)); states.addState(new int[] { }, getResources().getDrawable(R.drawable.normal)); imageView.setImageDrawable(states); //YOUR IMAGE HERE //AND FOR BUTTON button.setBackgroundDrawable(states);//FOR BUTTON</span>