Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I made it by override Button class</p> <pre><code>public class MButton extends Button { public MButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public MButton(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } public MButton(Context context) { super(context); // TODO Auto-generated constructor stub } //define style public void setPressedBg(Integer[] mImageIds) { StateListDrawable bg = new StateListDrawable(); Drawable normal = this.getResources().getDrawable(mImageIds[0]); Drawable selected = this.getResources().getDrawable(mImageIds[1]); Drawable pressed = this.getResources().getDrawable(mImageIds[2]); bg.addState(View.PRESSED_ENABLED_STATE_SET, pressed); bg.addState(View.ENABLED_FOCUSED_STATE_SET, selected); bg.addState(View.ENABLED_STATE_SET, normal); bg.addState(View.FOCUSED_STATE_SET, selected); bg.addState(View.EMPTY_STATE_SET, normal); this.setBackgroundDrawable(bg); } //define style public void setPressedBg(Integer p1,Integer p2,Integer p3) { StateListDrawable bg = new StateListDrawable(); Drawable normal = this.getResources().getDrawable(p1); Drawable selected = this.getResources().getDrawable(p2); Drawable pressed = this.getResources().getDrawable(p3); bg.addState(View.PRESSED_ENABLED_STATE_SET, pressed); bg.addState(View.ENABLED_FOCUSED_STATE_SET, selected); bg.addState(View.ENABLED_STATE_SET, normal); bg.addState(View.FOCUSED_STATE_SET, selected); bg.addState(View.EMPTY_STATE_SET, normal); this.setBackgroundDrawable(bg); } </code></pre> <p>}</p> <p>in my main()</p> <pre><code>toneButton.setPressedBg(R.drawable.button_tone_protrait_pipa, R.drawable.button_tone_protrait_pipa1, R.drawable.button_tone_protrait_pipa1); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload