Android Paint Setting flags

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

You can set the following flags in the constructor, or with setFlags(int flags)

  • Paint.ANTI_ALIAS_FLAG Enable antialiasing, smooths the drawing.
  • Paint.DITHER_FLAG Enable dithering. If color precision is higher than the device's, this will happen.
  • Paint.EMBEDDED_BITMAP_TEXT_FLAG Enables the use of bitmap fonts.
  • Paint.FAKE_BOLD_TEXT_FLAG will draw text with a fake bold effect, can be used instead of using a bold typeface. Some fonts have styled bold, fake bold won't
  • Paint.FILTER_BITMAP_FLAG Affects the sampling of bitmaps when transformed.
  • Paint.HINTING_OFF, Paint.HINTING_ON Toggles font hinting, see this
  • Paint.LINEAR_TEXT_FLAG Disables font scaling, draw operations are scaled instead
  • Paint.SUBPIXEL_TEXT_FLAG Text will be computed using subpixel accuracy.
  • Paint.STRIKE_THRU_TEXT_FLAG Text drawn will be striked
  • Paint.UNDERLINE_TEXT_FLAG Text drawn will be underlined

You can add a flag and remove flags like this:

Paint paint = new Paint();
paint.setFlags(paint.getFlags() | Paint.FLAG);   // Add flag
paint.setFlags(paint.getFlags() & ~Paint.FLAG);  // Remove flag

Trying to remove a flag that isn't there or adding a flag that is already there won't change anything. Also note that most flags can also be set using set<Flag>(boolean enabled), for example setAntialias(true).

You can use paint.reset() to reset the paint to its default settings. The only default flag is EMBEDDED_BITMAP_TEXT_FLAG. It will be set even if you use new Paint(0), you will have



Got any Android Question?