How to capitalize the first letter of text in a TextView in an Android Application

前端 未结 11 1697
孤街浪徒
孤街浪徒 2020-12-23 15:35

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 Capitaliz

11条回答
  •  隐瞒了意图╮
    2020-12-23 16:17

    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()));
    

提交回复
热议问题