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.


当前回答

如果您在styles.xml中编写样式,那么

删除android:inputType属性并添加以下行

<item name="android:capitalize">words</item>

其他回答

静态地(即在你的布局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);

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

-谷歌文档

以前它是android:capitalize="words",现在已弃用。建议使用android:inputType="textCapWords"

请注意,这将只在您的设备键盘自动大写设置启用。

要通过编程实现,请使用以下方法:

setInputType (InputType。TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);

在XML编辑文本中应用以下行。

android:inputType="textCapSentences|textMultiLine"

它还允许多线支持。

在XML和JAVA文件中设置输入类型,

在XML中,

android:inputType=“textMultiLine|textCapSentences”

它也将允许多行和在JAVA文件,

edittext.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

确保你键盘的自动大写设置是启用的。

以编程方式

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