I need to show a large number of EditText controls on a screen, each of which will only allow entering 0-2 digits. The default EditText size is too wide for me to show enough EditText controls on a screen, but I have been unable to figure out how to make them narrower. I have tried the following attributes in
XML:
android:maxLength="2"
android:layout_width="20dip"
android:maxWidth="20px"
android:ems="2"
android:maxEms="2"
So the question is: how can EditText be made smaller than default?
Try this way instead, shows the difference. Use the layout_width with the specified width.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:width="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText
android:layout_width="40dip"
android:layout_height="wrap_content"
android:text="@string/hello"
android:maxLength="2"
/>
</LinearLayout>
Hey once you try this,it may work....... android:textAppearance="?android:attr/textAppearanceSmall"
In case you end up on this page to search how to achieve the same in Java code..
txtSample.setFilters(new InputFilter[]{new InputFilter.LengthFilter(2)});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With