Letter Spacing in EditText for Android

9.5k views Asked by At

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

2

There are 2 answers

0
Ann83 On

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.

0
Joris Kroos On

This question is related to How to change letter spacing in a Textview?

As shown at this issue: android format edittext to display spaces after every 4 characters a solution might be to insert spaces with Java code...

You need to use TextWatcher to achieve visual purpose spaces.

And use any simply split string by space logic to join it back or loop through the entire string per character wise and eliminate (char) 32 from the string

As far as i know actual character spacing is not possible, though i'd love to use that myself as well.

Another option might be to use a custom font with the character spacing included.