0

Is it possible to create a button with round edges without using a shape XML in my drawable folder?

My app has a lot of buttons that will change colors based on what the user assigns and touches. This will mean I will have to create a lot of shapes in my xml for it's specific color (have about 20 colors).

Or is there a way I can easily change the background color of my shape's button? I have about 45 buttons on one page of in my app.

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • you can get the background of your button and change the color without creating hundreds of shapes. See here:https://stackoverflow.com/questions/17823451/set-android-shape-color-programmatically – Opiatefuchs Jul 05 '17 at 02:48

1 Answers1

0

You can use imageView.setColorFilter(Color.RED) function to change color of xml drawable

here are some example

ImageView redCircle = (ImageView) findViewById(R.id.circle_red_imageview);
ImageView greenCircle = (ImageView) findViewById(R.id.circle_green_imageview);
ImageView blueCircle = (ImageView) findViewById(R.id.circle_blue_imageview);

// we can create the color values in different ways:
redCircle.getDrawable().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY );
greenCircle.getDrawable().setColorFilter(0xff00ff00, PorterDuff.Mode.MULTIPLY );
blueCircle.getDrawable().setColorFilter(getResources().getColor(R.color.blue), PorterDuff.Mode.MULTIPLY );
Rajesh N
  • 6,198
  • 2
  • 47
  • 58