3

I want to set letter spacing on a EditText but it is not working.

I tried to create the EditText like this:

 <EditText
                android:id="@+id/pin"
                android:layout_width="match_parent"
                android:layout_height="@dimen/input_text_height"
                android:textSize="@dimen/text_size_extra_large"
                local:MvxBind="Text PinCode"
                android:maxLength="6"
                android:layout_marginRight="32dp"
                android:layout_marginLeft="32dp"
                android:layout_marginTop="10dp"
                android:padding="6dp"
                android:gravity="center"
                android:textColor="@drawable/editText_textColorState"
                android:background="@drawable/editText_borderOnFocus"
                android:letterSpacing="10"/>

The letter spacing attribute is not working. What am I doing wrong?

Kam
  • 391
  • 1
  • 3
  • 12

3 Answers3

12

letterSpacing need to be a float value. Try android:letterSpacing="0.50"

Like @mike points out Android Studio does render letter spacing in preview since V4.0

Old Answer

Android Studio doesn't render the letter spacing in the preview, so you will have to manual run it on a device to view the changes.

Saran Sankaran
  • 2,335
  • 2
  • 19
  • 34
  • 1
    Just a little note for future readers: in Android Studio 4.0.1 and beyond letter spacing is updated in real time in the preview – Michele Aug 15 '20 at 10:20
2

In the official documentation, they've mentioned that it requires a float value instead of an integer.

android:letterSpacing Text letter-spacing.

May be a floating point value, such as "1.2".

android:letterSpacing="1.2"

So, your EditText should look like this

<EditText
    android:id="@+id/pin"
    android:layout_width="match_parent"
    android:layout_height="@dimen/input_text_height"
    android:textSize="@dimen/text_size_extra_large"
    local:MvxBind="Text PinCode"
    android:maxLength="6"
    android:layout_marginRight="32dp"
    android:layout_marginLeft="32dp"
    android:layout_marginTop="10dp"
    android:padding="6dp"
    android:gravity="center"
    android:textColor="@drawable/editText_textColorState"
    android:background="@drawable/editText_borderOnFocus"
    android:letterSpacing="10.0"/>
Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60
0

You have to ommit units, type just value:

android:letterSpacing="1.2"

For some reason letterSpacing wasn't changing in the AS preview. I had to actually run the app on a physical device to see the change

Kanwarpreet Singh
  • 2,037
  • 1
  • 13
  • 28