I'm not referring to textInput, either. I mean that once you have static text in a TextView (populated from a Database call to user inputted data (that may not be Capitalized)), how can I make sure they are capitalized?
Thanks!
If you are using an Android phone and Gboard, you can capitalize the first letter of any word with three touches. First, double-tap the word in question to highlight the word, then tap the shift button (the up arrow) on the keyboard to capitalize the first letter. Done!
Update. You can now use textAllCaps to force all caps. One of the answers on the linked question suggests 'android:textAllCaps="true"' This worked for me. You can do that using "textAllCaps" attribute, hence the downvote.
To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.
I should be able to accomplish this through standard java string manipulation, nothing Android or TextView specific.
Something like:
String upperString = myString.substring(0, 1).toUpperCase() + myString.substring(1).toLowerCase();
Although there are probably a million ways to accomplish this. See String documentation.
EDITED I added the .toLowerCase()
Following does not apply to TextView, but works with EditText; even then, it applies to the text entered from the keyboard, not the text loaded with setText(). To be more specific, it turns the Caps on in the keyboard, and the user can override this at her will.
android:inputType="textCapSentences"
or
TV.sname.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
This will CAP the first letter.
or
compile 'org.apache.commons:commons-lang3:3.4' //in build.gradle module(app) tv.setText(StringUtils.capitalize(myString.toLowerCase().trim()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With