Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. Button btn = (Button) findViewById(R.id.button);
  2.  
  3. Bitmap pressBmp = BitmapFactory.decodeResource(getResources(), R.drawable.press);
  4. Bitmap checkBmp = BitmapFactory.decodeResource(getResources(), R.drawable.check);
  5. Bitmap normalBmp = BitmapFactory.decodeResource(getResources(), R.drawable.normal);
  6.  
  7. Drawable pressDraw = new BitmapDrawable(getResources(), pressBmp);
  8. Drawable checkDraw = new BitmapDrawable(getResources(), checkBmp);
  9. Drawable normalDraw = new BitmapDrawable(getResources(), normalBmp);
  10.  
  11. StateListDrawable drawable = new StateListDrawable();
  12. drawable.addState(new int[]{android.R.attr.state_pressed}, pressDraw);
  13. drawable.addState(new int[]{android.R.attr.state_selected}, checkDraw);
  14. drawable.addState(new int[]{}, normalDraw);
  15.  
  16. btn.setBackground(drawable);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement