Reputation: 31130
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?
Upvotes: 6
Views: 15746
Reputation: 2587
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>
Upvotes: 10
Reputation: 11
When in a table, as you describe, android:layout_gravity="left" will collapse the EditText to to the stated size of the EditText
Upvotes: 1
Reputation: 4832
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)});
Upvotes: 1
Reputation: 41
Hey once you try this,it may work....... android:textAppearance="?android:attr/textAppearanceSmall"
Upvotes: 4