2

In the spirit of simple vector images on Android that always look sharp, I was wondering if I can't use custom font paired with a string (or a character) as a Drawable.

For instance, if I wanted to use a Webdings character as the drawable on a Button, how would I do this?

I want the best font size to be selected (using dip or sp) so that I get no distortion on the image.

Do you have any ideas how I can accomplish this goal?

Thanks!

Brett
  • 4,066
  • 8
  • 36
  • 50
  • If that's what you want, why not use a text label on the button? Which is what a default button has (ImageButton is the one that uses an image). – Gabe Sechan Feb 26 '13 at 20:22
  • It really needs to be a drawable. What if I wanted to display an icon in the drawableLeft portion of an EditText? Same problem... – Brett Feb 26 '13 at 20:28
  • This is a related issue: http://stackoverflow.com/a/8831182/602245 – Brett Feb 26 '13 at 20:29
  • Yeah it is related, but it is not the same: Brett wants something that adjusts font size and so on. It is entirely possible: Simply a matter of Programming. Extending Drawable in this way, though, is going to be a fair amount of work... – G. Blake Meike Feb 26 '13 at 22:19
  • Check my answer here http://stackoverflow.com/a/40692513/4291698 – sanket vetkoli Nov 21 '16 at 07:22

1 Answers1

2

You can check out my library IconicTextView It allows to use several iconic fonts to display vector images. Currently a subclass of TextView is used to display them but I'm working on rewriting it to use custom Drawable. The main issue here is selecting the best font size, I'm trying to find a way to auto adjust font size.

atermenji
  • 1,338
  • 8
  • 19
  • The ability to automatically adjust font size would be critical to me here, thanks! – Brett Mar 22 '13 at 14:00
  • 1
    Hi @Brett! I've updated the library. Now there is a class called IconicFontDrawable (https://github.com/atermenji/IconicTextView/blob/master/library/src/com/atermenji/android/iconictextview/IconicFontDrawable.java). It draws an icon from custom iconic font and automatically adjusts text size to container bounds. – atermenji Apr 12 '13 at 10:29