How to make EditText start capitalized?

I have an EditText , and I need the text in it (when the user entered) to start with a capital letter.

+72
android
Sep 12 '11 at 10:13 on
source share
12 answers

Be careful if you add both android:capitalize="sentences" and android:inputType="text" , since the latter, apparently, takes precedence over the first, and the input will not be capitalized.

There is a special inputType for the automatic first letter of the first letter:

android:inputType="textCapSentences"

See http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType

+143
Oct 24 '11 at 11:00
source share

Android Options : Caps are

 android:capitalize="none", which won't automatically capitalize anything. android:capitalize="sentences", Which will capitalize the first word of each sentence. android:capitalize="words", Which Will Capitalize The First Letter Of Every Word. android:capitalize="characters", WHICH WILL CAPITALIZE EVERY CHARACTER. 

Obviously it was changed to inputType instead of capitalize

+21
Aug 10 '12 at 15:00
source share

Using

 android:inputType="textPersonName|textCapWords" 

since using only "textPersonName" not enough, so the first letter names will be capitalized.

Similar to postal addresses:

 android:inputType="textPostalAddress|textCapSentences" 
+12
Aug 14 '14 at 8:30
source share

Add this to your XML

  android:inputType="textCapWords" 

android:inputType="textCapSentences" will work for sentences. However, I had to use every word in the full name field.

+8
May 29 '14 at 12:05
source share

Try this way

 testEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS); 

or android:inputType="textCapSentences" will only work if automatic device keyboard tuning is enabled.

+6
Mar 11 '14 at 9:48
source share

In the xml layout add android:inputType=textCapSentences

+3
Jan 09 '13 at
source share

In the xml layout add android:capitalize="sentences"

+2
Sep 12 '11 at 10:15
source share

You used the word "Enforce". So try this one. Just pass your edittext as an argument.

 public static void setCapitalizeTextWatcher(final EditText editText) { final TextWatcher textWatcher = new TextWatcher() { int mStart = 0; @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { mStart = start + count; } @Override public void afterTextChanged(Editable s) { String input = s.toString(); String capitalizedText; if (input.length() < 1) capitalizedText = input; else capitalizedText = input.substring(0, 1).toUpperCase() + input.substring(1); if (!capitalizedText.equals(editText.getText().toString())) { editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { editText.setSelection(mStart); editText.removeTextChangedListener(this); } }); editText.setText(capitalizedText); } } }; editText.addTextChangedListener(textWatcher); } 
+2
Nov 19 '15 at 10:07
source share

In the case of a password that starts with an uppercase, it will:

android:inputType="textPassword|textCapSentences"

+2
Sep 16 '18 at 20:52
source share

Paste this into your edittext (xml):

  android:capitalize="sentences" 
+1
Mar 18 '14 at 6:25
source share
 edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()}); 
+1
Mar 16 '16 at 7:31
source share

in case you encounter the annoying case of setting android: inputType = textCapSentences followed by a single-line EditText, here is the solution:

  android:inputType="textCapSentences|textMultiLine" 
0
Jan 30 '19 at 11:52
source share



All Articles