Reputation: 116060
Short question:
Suppose I have a TextView, and I wish that the text itself (not the backround) will have a drawable set to it (and not just a solid color), how should I do it?
The only solution I've found is this one , but it's only for gradient colors, and I wish to be able to use any drawable.
Upvotes: 2
Views: 1242
Reputation: 116060
Ok, I think I've found a possible solution, but I have some notes about it:
It's not for any drawable. It's for a bitmap, so you will need to somehow convert it to a bitmap.
It requires that you know the size of the textView (which you can use this for this purpose)
It requires that you have enough memory for the scaled bitmap that is in the same size of the textView.
Not sure how to make it work per character or per line.
Here's the code:
public static void setBitmapOnTextView(final TextView tv, final Bitmap bitmap) {
final TileMode tile_mode = TileMode.CLAMP;
final int height = tv.getHeight();
final int width = tv.getWidth();
final Bitmap temp = Bitmap.createScaledBitmap(bitmap, width, height, true);
final BitmapShader bitmapShader = new BitmapShader(temp, tile_mode, tile_mode);
tv.getPaint().setShader(bitmapShader);
}
I hope that there is a better solution for this.
Upvotes: 2
Reputation: 39856
edited:
I don't believe it's possible to change the actual stroke used on the text, the best closest option you probably have is to use a different font.
In android you can "draw" any text using any *.ttf font.
for that you must include the file in your assets folder and call from code (maybe there's a way using XML, but I don't know how) this:
TypeFace mFont = TypeFace.createFromAsset(mContext.getAssets(), "my_font.ttf");
mTextView.setTypeFace(mFont);
I reckon that is the closes you'll get to have a different stroke on the text.
original answer:
TextView have the following properties:
Drawable Top
Drawable Bottom
Drawable Left
Drawable Right
that you set on the XML. Or you can call
setCompoundDrawables(left, top, right, bottom)
from code!
Upvotes: 0