Definition of style, color, etc. In XML?

I use a fairly simple drawing in the application I'm working on, and wonder about the β€œright” way to handle Paint attributes such as color, etc. With lines, styles, menus, layouts, etc., separated from the application logic and defined in XML, I was wondering how (if possible) to define the "Paint" style in XML in much the same way.

I performed a series of searches and came up empty, which may be the answer, but I wondered about other approaches than, say:

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

Thanks,

Floor

+6
android xml coding-style paint
source share
1 answer

As far as I know, there is no way to define the drawing style in the XML resource file of Android. However, you can define the necessary values ​​(integers, colors, etc.) in the XML resource and then manually load them into the Paint object. It is still hard-coded, but at least you can define colors, etc. In your resource file once and use them in different places later. :-)

+4
source share

All Articles