Guest User

Untitled

a guest
Aug 14th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. Get the background color of a button in android
  2. android:tag="#ff0000"
  3.  
  4. String colorCode = (String)btn.getTag();
  5.  
  6. Button button = (Button) findViewById(R.id.my_button);
  7. Drawable buttonBackground = button.getBackground();
  8.  
  9. ColorDrawable buttonColor = (ColorDrawable) button.getBackground();
  10.  
  11. int colorId = buttonColor.getColor();
  12.  
  13. if (colorID == R.color.green) {
  14. log("color is green");
  15. }
  16.  
  17. public Drawable getBackground();
  18.  
  19. public int getColor()
Add Comment
Please, Sign In to add comment