I'm doing an AppWidget and in its settings I'm letting the user enable/disable text shadow. Since I can't invoke the shadow method through the RemoteViews class, I'm doing a "draw" method that dynamically paints the widget and its container.
When drawing the text though, it gets kinda blurred and not that crisp like when using a TextView. The only code I've used for the text painting is:
Paint p = new Paint();
p.setAntiAlias(true);
p.setColor(Color.WHITE);
Are there any other magic I need to do for it to become more crisp?
This article explains how to draw text inside a rectangle using the canvas in Android. Android Studio is used for the sample. In this, you will first create a paint object. Then call the setColor() method of paint to set the color of the rectangle by ing a color variable.
Another (arguably better) way to draw text on a canvas is to use a StaticLayout . This handles multiline text when needed. String text = "This is some text."; TextPaint textPaint = new TextPaint(); textPaint. setAntiAlias(true); textPaint.
Use the Canvas method public void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint) . Set dst to the size of the rectangle you want the entire image to be scaled into. EDIT: Here's a possible implementation for drawing the bitmaps in squares across on the canvas.
To draw onto a canvas in Android, you will need four things: A bitmap or a view — to hold the pixels where the canvas will be drawn. Canvas — to run the drawing commands on. Drawing commands — to indicate to the canvas what to draw.
Paint paint = new Paint(Paint.LINEAR_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
did the trick for me
These are my text paint settings:
textPaint = new Paint();
textPaint.setStyle(Paint.Style.FILL);
textPaint.setAntiAlias(true);
textPaint.setARGB(255, 255, 255, 255);
textPaint.setFakeBoldText(true);
textPaint.setTextSize(textSize);
Seems to be working well for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With