How to select different colors from ColorPicker and apply it to text or other shapes on the same screen in Android?

enter image description here

If the user picks any color from the colorpicker, he should be able to apply it to text or other shapes in the same action or screen in Android.

I have shapes and a set of colors on my screen. Using the onTouch event, I could draw different shapes. Also I can write anything on the screen. In my application, the color picker function works fine.

First - if I draw a triangle and write some text like "meena" then apply blue from color picker it works fine

In the second - on the same screen (below the text "meena") I clicked the rose color from the color picker and chose different shapes like a rectangle and I wrote the word apple. This time I have already chosen the color of the rose.

So, starting with the first and second steps, all the different forms and words are applied in pink.

My question is, how can a user select different colors from a set of colors and can write text or draw different shapes of different colors on the touchscreen using a touch event in the same action or screen? Thus, different colors can be found all over the screen.

But my problem is only one color is applied on the whole screen.

I want to apply colors from a color picker to text on the same screen or in such a way. See above picture for reference.

+3


source to share


1 answer


You need you to use paint and change the paint color selected by color picker and invalidate a code like this.

public class DrawPaint extends View{
Paint textPaint = new Paint();
Paint circlePaint = new Paint();

public DrawPaint(Context context){
    super(context);
    //set default colors for them 
    textPaint.setColor(Color.RED);
    circlePaint.setColor(Color.GREEN);
}

@Override
protected void onDraw(Canvas canvas){
    super.onDraw(canvas);
    canvas.drawText("mu text " , 0 , 0 , textPaint);
    canvas.drawCircle(10 , 10 , 20 , circlePaint);
}

public void changeTextColor(int color){
    textPaint.setColor(color);
    invalidate();
}

public void changeCircleColor(int color){
    circlePaint.setColor(color);
    invalidate();
}
}

      



get a link to this view and when you get the color from the changeColor color picker method

or Here is a working solution for Finger-Paint

0


source







All Articles