如何利用在Android的EditText每一个字母? [英] How to capitalize every letter in an Android EditText?

查看:121
本文介绍了如何利用在Android的EditText每一个字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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?

推荐答案

您需要告诉它这是从类文本:

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

借助输入类型是一个的掩码。您可以通过将结合标志| (管)字在中间,它代表或逻辑功能,即使在一个位掩码像这样使用时,它的意思是这个标志,而其他标志。

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".

(这个答案是一样的知更鸟的,但没有幻数,你可以把你的code。将Android的API有常数最糟糕的事情之一,而不是使用复制的价值和冒险,最终他们突破code)

(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每一个字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆