How to capitalize every letter in an Android EditT

2020-03-08 08:03发布

I have an array of editTexts which I make like this:

        inputs[i] = new EditText(this);
        inputs[i].setWidth(376);
        inputs[i].setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
        tFields.addView(inputs[i]);

I want every character to be capitalized. Right now, the first letter of the first word is lowercase, then all the characters afterwords are upper case. I can take what the user inputs after they are done and convert that to uppercase, but that's not really what I'm going for. Is there a way to get these fields to behave the way I want them to?

10条回答
叼着烟拽天下
2楼-- · 2020-03-08 08:36

To capitalize the first word of each sentence use :

android:inputType="textCapSentences"

To Capitalize The First Letter Of Every Word use :

android:inputType="textCapWords"

To Capitalize every Character use :

android:inputType="textCapCharacters"

查看更多
\"骚年 ilove
3楼-- · 2020-03-08 08:38

As of today, Its

android:inputType="textCapCharacters"

查看更多
我想做一个坏孩纸
4楼-- · 2020-03-08 08:41

This would work

    inputs[i] = new EditText(this);
    inputs[i].setWidth(376);
    inputs[i].setInputType(0x00001001);
    tFields.addView(inputs[i]);

0x00001001 corresponds to "textCapCharacters constant.

查看更多
▲ chillily
5楼-- · 2020-03-08 08:45

This will make all the characters uppercase when writing.

edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});

Original answer here.

查看更多
走好不送
6楼-- · 2020-03-08 08:45

You can try this:

android:inputType="textCapCharacters"

It worked for me. =)

查看更多
地球回转人心会变
7楼-- · 2020-03-08 08:46

try using this single line of code in your xml:

android:capitalize="sentences"
查看更多
登录 后发表回答