I have an EditText
and I need the text in it (when user types in) to be started with capital letter.
13 Answers
Be careful if you add both android:capitalize="sentences"
and android:inputType="text"
, as the latter seems to have priority over the first and the input will not be capitalized.
There's a specific inputType
for automatically capitalizing the first letter:
android:inputType="textCapSentences"
See http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType

- 8,022
- 3
- 31
- 66

- 37,861
- 14
- 95
- 96
-
1Nice tip! I had both and it worked as expected on a Nexus One and a Galaxy Nexus. But on an HTC Sense device, the words were not capitalized. android:inputType was the trick. – BoD Sep 14 '12 at 12:45
-
10Word of warning: since in my case the field was going to be a person's name, I set android:inputType="textPersonName". This did not work as expected: I had to use android:inputType="textCapWords" to get each word of the name to capitalize. – Jeff G Nov 15 '12 at 10:37
-
2android:capitalize="sentences" should not use this tag bcuz it is deprecated – pioneerBhawna Nov 22 '13 at 14:06
-
What if android:inputType="textMultiLine"? – KRP May 23 '14 at 07:14
-
14Then use `android:inputType="textMultiLine|textCapSentences"` – 4mnes7y Nov 18 '14 at 16:06
-
Its not working with google material **om.google.android.material.textfield.TextInputEditText** – Arbaz.in Aug 27 '19 at 09:38
The options for android:capitalize are
android:inputType="none", which won't automatically capitalize anything.
android:inputType="sentences", Which will capitalize the first word of each sentence.
android:inputType="words", Which Will Capitalize The First Letter Of Every Word.
android:inputType="characters", WHICH WILL CAPITALIZE EVERY CHARACTER.
Apparently it has been changed to inputType
instead of capitalize

- 5,217
- 4
- 44
- 61
-
3
-
-
-
@SadiqueKhan would you mind adding to the answer with an edit? I answered this 10 years ago. I would hope that the syntax has changed a bit. – DeadlyChambers Sep 15 '22 at 22:59
-
Use
android:inputType="textPersonName|textCapWords"
as using only "textPersonName"
is not enough so name's first letters would be capitalized.
Similarly with postal addresses:
android:inputType="textPostalAddress|textCapSentences"

- 11,345
- 4
- 67
- 71
Try this way,
testEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
or android:inputType="textCapSentences"
will only work If your device keyboard Auto Capitalize Setting enabled.

- 74,896
- 15
- 165
- 198

- 1,671
- 2
- 26
- 42
-
accepted answer is great but I was looking for coding answer, this works. tx – Boris Gafurov Apr 18 '16 at 17:31
Add this in your XML
android:inputType="textCapWords"
android:inputType="textCapSentences"
will work for sentences. However, I needed to capitalize every word in a full name field.

- 74,896
- 15
- 165
- 198

- 81
- 1
- 3
You used the word "Enforce". So try this. Just pass your edittext as 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);
}

- 1,378
- 11
- 20
In case of password which starts from upper case it will be:
android:inputType="textPassword|textCapSentences"

- 329
- 2
- 4
in case you ran into the annoying case of setting android:inputType=textCapSentences then ending up with one-liner EditText, here's the solution:
android:inputType="textCapSentences|textMultiLine"

- 1,879
- 20
- 14
edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
-
While this code snippet may solve the question, [including an explanation](https://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – Box Box Box Box Jun 18 '16 at 11:27
Adding input type in edit text as textCapSentences which will make first letter of the sentence capital
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:padding="10dp"
android:gravity="center"
android:inputType="textCapSentences"
android:hint="Name"/>

- 230
- 3
- 9