I have a simple EditText with layout_width="wrap_content"
. There are no paddings or margins in attributes. Here is a full example:
<EditText
android:id="@+id/maskPrefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="3"
android:inputType="text|textCapCharacters|textNoSuggestions"
android:maxLength="5"
android:maxLines="1"
android:nextFocusDown="@+id/maskNum"
android:text="GA"
android:textSize="18sp"
tools:ignore="LabelFor" />
Everything is fine but... But:
- When I set ems to 1, it is about 1 char wide;
- When I set ems to 2, It is about 2.5 chars wide;
- When I set ems to 3, It is about 4.5 chars wide;
- When I set ems to 4, It is about 6 chars wide;
- When I set ems to 5, It is about 10 chars wide;
- When I set ems to 10, It is about 20 chars wide;
If I remove android:ems
and instead set max width via android:maxLength
, then everything is appropriate width. But I need both attributes.
Why is my EditText
width wrong? What's with this mysterious multiplier? I use Theme.AppCompat.Light.NoActionBar
, latest android studio (2.2.2) and compile with
compile "com.android.support:support-v4:25.0.1"
compile 'com.android.support:appcompat-v7:25.0.1'
Testing with Android 6 in Nexus 5.
What option or attribute could mess android:ems
so badly?
UPD. Link to this question does not solve my problem in any way. Also, it is absolutely correct to set both android:textSize
and android:ems
. I want letters of my text to be x sp large and I want my EditText
to be y chars wide.