Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make EditText smaller than default?

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?

like image 490
Heikki Toivonen Avatar asked Mar 17 '09 05:03

Heikki Toivonen


3 Answers

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>

alt text

like image 112
Feet Avatar answered Sep 19 '22 01:09

Feet


Hey once you try this,it may work....... android:textAppearance="?android:attr/textAppearanceSmall"

like image 30
jetti Avatar answered Sep 22 '22 01:09

jetti


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)});
like image 43
Niks Avatar answered Sep 19 '22 01:09

Niks