Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android set button with customerized color and round corner programmatically

Tags:

android

button

I am now working on a drawing app, and users can select their customerized colors. Then the customerized color button would then be showing the chosen color. However, it become squared-corner once it was set to be the customerized color.

My coding is as follows:

My question is :

  1. How to set the customBtn such that it is round-corner and filled with customerized color (best to be programmatically as the customerized color will be changed upon user's choice)

  2. actually what are those 10 for the new float[] array represent?

Many thanks!!

Coding:

 customColorCode = Color.argb(alphaSeekBar.getProgress(), redSeekBar.getProgress(), 
         greenSeekBar.getProgress(), blueSeekBar.getProgress());         



 RoundRectShape rs = new RoundRectShape(new float[] { 10, 10, 10, 10, 10, 10, 10, 10}, null, null);
 ShapeDrawable sd = new ShapeDrawable(rs);
 customBtn.setBackgroundDrawable(sd);
 customBtn.setBackgroundColor(customColorCode);
like image 479
pearmak Avatar asked Jan 17 '26 17:01

pearmak


1 Answers

  1. change background color to set the different colors to button
  2. public RoundRectShape (float[] outerRadii, RectF inset, float[] innerRadii) Added in API level 1 RoundRectShape constructor. Specifies an outer (round)rect and an optional inner (round)rect.

Parameters outerRadii An array of 8 radius values, for the outer roundrect. The first two floats are for the top-left corner (remaining pairs correspond clockwise). For no rounded corners on the outer rectangle, pass null. inset A RectF that specifies the distance from the inner rect to each side of the outer rect. For no inner, pass null. innerRadii An array of 8 radius values, for the inner roundrect. The first two floats are for the top-left corner (remaining pairs correspond clockwise). For no rounded corners on the inner rectangle, pass null. If inset parameter is null, this parameter is ignored.

like image 196
Hamad Avatar answered Jan 20 '26 09:01

Hamad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!