問題描述
我有一個這樣的editTexts數組:
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?
推薦答案
你也需要告訴它來自class"文本:
You need to tell it it's from the "class" text as well:
inputs[i] = new EditText(this);
inputs[i].setWidth(376);
inputs[i].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
tFields.addView(inputs[i]);
輸入類型是一個位掩碼.您可以通過放置 | 來組合標志.(管道)字符在中間,它代表 OR 邏輯函數,即使在像這樣的位掩碼中使用它意味著這個標志和那個另一個標志".
The input type is a bitmask. You can combine the flags by putting the | (pipe) character in the middle, which stands for the OR logic function, even though when used in a bitmask like this it means "this flag AND that other flag".
(此答案與 Robin 的答案相同,但沒有幻數",這是您可以在代碼中放入的最糟糕的事情之一.Android API 具有常量,請使用它們而不是復制值并冒最終破壞代碼的風險.)
(This answer is the same as Robin's but without "magic numbers", one of the worst things you can put in your code. The Android API has constants, use them instead of copying the values and risking to eventually break the code.)
這篇關于如何大寫Android EditText中的每個字母?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!