Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Letter Spacing in EditText for Android

I am trying to have a custom EditText based on the background that i am using for. The Background image has some spaces between the entry areas so i need to have some space between the characters(kerning) to fit them right in. So for example after every character the user enters, i need to put 4 whitespace after that.

I couldn't find any solution for this on the net so far, some people suggested TextWatcher, but i couldn't manage to make it work as i want it too.

Can someone help me about it?

Thanks

like image 261
koraxis Avatar asked Nov 12 '22 22:11

koraxis


1 Answers

I have you considered using a custom font? Some font types are made to stretch out or shrink or have empty spaces. With so many different fonts available online, you can definitely find something. You can also make your own with a software. It might be time consuming if you start the lettering from scratch. I'm not 100% sure if it'll fit exactly to your background, but it's idea that you can consider.

If it doesn't fit, I supposed you can always customized the background to fix your font too. Here's the code for those who might want to use custom fonts in their app too.

Typeface myfont = Typeface.createFromAsset(getAssets(),
          "fonts/Blocks2.ttf");

myeditText.setTypeface(myfont);

The font is in the asset folder under another folder called fonts.

like image 189
Ann83 Avatar answered Nov 15 '22 02:11

Ann83