I would like to create an EditText which accepts only numbers, has a maximum of 4 numbers, and is never narrower than it would be if filled with 4 numbers (does not shrink when empty, or have to expand to accommodate 4 numbers, so it's fixed.)
The first 2 are accomplished with: android:inputType="number" and android:maxLength="4".
How can I set the minimum length?
You can set alignment other wise when you put character more than wditText width than It's increase width or EditText width. Please set toLeftOf and toRightOf of the above view to manage this things. Only one solution
The problem is, that an EditText widget can loss focus because of a lot of different actions like touching another sensitive view, menu button or (hard keyboard cursor control) and so on. The restiction of a maximum length or type of the input can be done during the tying process (accept the character if it passes the filter or the length is not exceeded). but focus lost can be occour every time - even the submission is not completed yet and the input to short -> therefore there is no build-in minimum length solution, because the application would block at this point the execution of another event or task. At least you have to validate your input before going to the next step in your workflow.
I use android:layout_width="60dip" so agree with mike fratto.
The ems solution appears to be interesting as well.
Phil
One rarely-used (AFAIK) attribute of an EditText that you can use is:
android:ems="4"
This makes the EditText exactly 4 ems wide. An em width is the width of the widest (M) character in the selected font.