Qui ho scritto un articolo dettagliato sull'argomento, poiché abbiamo diverse opzioni, Capitalize First Letter of String in Android
Metodo per scrivere in maiuscolo la prima lettera di stringa in Java
public static String capitalizeString(String str) {
String retStr = str;
try { // We can face index out of bound exception if the string is null
retStr = str.substring(0, 1).toUpperCase() + str.substring(1);
}catch (Exception e){}
return retStr;
}
Metodo per scrivere in maiuscolo la prima lettera di stringa in Kotlin
fun capitalizeString(str: String): String {
var retStr = str
try { // We can face index out of bound exception if the string is null
retStr = str.substring(0, 1).toUpperCase() + str.substring(1)
} catch (e: Exception) {
}
return retStr
}
Utilizzo dell'attributo XML
Oppure puoi impostare questo attributo in TextView o EditText in XML
android:inputType="textCapSentences"