I'm working on a little personal todo list app and so far everything has been working quite well. There is one little quirk I'd like to figure out. Whenever I go to add a new item, I have a Dialog with an EditText view showing inside. When I select the EditText view, the keyboard comes up to enter text, as it should. In most applications, the default seems to be that the shift key is held for the first letter... although it does not do this for my view. There has to be a simple way to fix, but I've searched the reference repeatedly and cannot find it. I'm thinking there has to be an xml attribute for the reference loaded by the Adapter, but I can't find out what it is.


当前回答

静态地(即在你的布局XML文件):设置android:inputType=" textcapsentence "在你的EditText。

编程上:你必须包括InputType。在EditText的InputType中的TYPE_CLASS_TEXT,例如

EditText editor = new EditText(this); 
editor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

可以与文本及其变体相结合,以要求每个句子的第一个字符大写。

-谷歌文档

其他回答

对于EditText中的资本化,您可以选择以下两种输入类型:

android:inputType=“textCapSentences” android:inputType=“textCapWords”

textCapSentences 这将使每个句子中第一个单词的第一个字母成为大写字母。

textCapWords 这将使每个单词的第一个字母作为大写字母。

如果你想要两个属性都使用|符号

android:inputType="textCapSentences|textCapWords"

以编程方式

TextView firstline = (TextView) findViewById(R.id.firstline);
firstline.setAllCaps(true);

静态地(即在你的布局XML文件):设置android:inputType=" textcapsentence "在你的EditText。

编程上:你必须包括InputType。在EditText的InputType中的TYPE_CLASS_TEXT,例如

EditText editor = new EditText(this); 
editor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

可以与文本及其变体相结合,以要求每个句子的第一个字符大写。

-谷歌文档

只需在EditText元素中使用android:inputType="textCapWords"即可。

例如:

<EditText
    android:id="@+id/txtName"
    android:layout_width="0dp"
    android:layout_height="40dp"
    android:layout_weight="0.7"
    android:inputType="textCapWords"
    android:textColorHint="#aaa"
    android:hint="Name Surname"
    android:textSize="12sp" />

请参考以下链接: http://developer.android.com/reference/android/widget/TextView.html#attr_android%3ainputType

我也遇到了同样的问题,只是分享了我的发现。可能会帮助你和其他人…

在你的布局上试试这个。在EditText中添加下面的行。

android:inputType="textCapWords|textCapSentences"

对我来说很好..希望它也适用于你…