Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining a Paint style, color, etc in XML?

I'm doing some rather basic drawing in an app I am working on, and am wondering about the 'proper' way to handle defining the Paint's attributes, such as color, etc. With strings, styles, menus, layouts, etc being separated from app logic and defined in XML, I was wondering about how to (if possible) define a Paint 'style' in XML in much the same way.

I've done a number of searches and have come up empty, which may be the answer, but was wondering about other approaches than, say:

mPaint = new Paint();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(0x80808080);

Thanks,

Paul

like image 628
Unpossible Avatar asked Jan 10 '11 20:01

Unpossible


People also ask

What do you mean by color XML file?

colors. xml is an XML file which is used to store the colors for the resources.

What is paint Android studio?

The Paint class holds the style and color information about how to draw geometries, text and bitmaps.


1 Answers

As far as I know there is no possibility to define a paint style in an Android resource XML file. What you can do though is to define the necessary values (integers, colors, etc.) in a resource XML and load them to your Paint object later manually. It is still hardcoded somehow, but at least you can define colors etc. in your resource file once and use them at different locations later. :-)

like image 120
mreichelt Avatar answered Sep 21 '22 13:09

mreichelt