In Android EditText, how to force writing uppercase?

前端 未结 23 1832
后悔当初
后悔当初 2020-11-27 12:28

In my Android application I have different EditText where the user can enter information. But I need to force user to write in uppercase letters. Do you know a

23条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 12:41

    Rather than worry about dealing with the keyboard, why not just accept any input, lowercase or uppercase and convert the string to uppercase?

    The following code should help:

    EditText edit = (EditText)findViewById(R.id.myEditText);
    String input;
    ....
    input = edit.getText();
    input = input.toUpperCase(); //converts the string to uppercase
    

    This is user-friendly since it is unnecessary for the user to know that you need the string in uppercase. Hope this helps.

提交回复
热议问题