First letter capitalization for EditText
Solution 1:
Statically (i.e. in your layout XML file): set android:inputType="textCapSentences"
on your EditText
.
Programmatically: you have to include InputType.TYPE_CLASS_TEXT
in the InputType
of the EditText
, e.g.
EditText editor = new EditText(this);
editor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
Can be combined with text and its variations to request capitalization of the first character of every sentence.
- Google Docs
Solution 2:
Just use android:inputType="textCapWords"
in your EditText element.
For example:
<EditText
android:id="@+id/txtName"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.7"
android:inputType="textCapWords"
android:textColorHint="#aaa"
android:hint="Name Surname"
android:textSize="12sp" />
Refer to the following link for reference: http://developer.android.com/reference/android/widget/TextView.html#attr_android%3ainputType
Solution 3:
Apply following line in your EditText in XML.
android:inputType="textCapSentences|textMultiLine"
It will also allow multi-line support.