Android setup button with pre-programmed color and circular angle

Now I am working on a graphics application and users can choose the colors they use. Then the custom color button will show the selected color. However, it becomes square as soon as it is adjusted to the client's color.

My coding looks like this:

My question is:

  • How to set it customBtn

    so that it is round and filled with a colored user (best programmatically, as the client color will be changed at the user's choice)

  • In fact, what are those 10 for the new float [] array?

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);

      

+3


source to share


1 answer


  • change the background color to set different colors for the button
  • public RoundRectShape (float [] externalRadii, RectF inset, float [] internalRadii) Added in API Level 1 RoundRectShape constructor. Defines an outer (round) rectangle and an optional inner (round) rectangle.


Parameters outerRadii An array of 8 radius values, for outer rounding. The first two floats are for the top left corner (the rest of the pairs correspond clockwise). No rounded corners on the outer rectangle, omit null. insert A RectF that defines the distance from the inner rectangle to each side of the outer rectangle. Null is accepted for neither internal. innerRadii An array of 8 radius values ​​to use for inner rounding. The first two floats are for the top left corner (the rest of the pairs correspond clockwise). Do not accept zero for rounded corners on the inner rectangle. If the insert parameter is null, this parameter is ignored.

+1


source







All Articles