EditText 的首字母大写

First letter capitalization for EditText(EditText 的首字母大写)

本文介绍了EditText 的首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型个人待办事项列表应用程序,到目前为止一切都运行良好.我想弄清楚一个小怪癖.每当我去添加一个新项目时,我都会有一个对话框,里面显示一个 EditText 视图.当我选择 EditText 视图时,键盘会按原样输入文本.在大多数应用程序中,默认值似乎是第一个字母的 shift 键......尽管在我看来它并没有这样做.必须有一种简单的方法来修复,但我反复搜索了参考资料,但找不到.我在想适配器加载的引用必须有一个 xml 属性,但我不知道它是什么.

解决方案

静态(即在你的布局 XML 文件中):在你的 EditText 上设置 android:inputType="textCapSentences"代码>.

以编程方式:您必须在 EditTextInputType 中包含 InputType.TYPE_CLASS_TEXT,例如

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

<块引用>

可以结合文本及其变体来请求每个句子的第一个字符大写.

- Google 文档

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.

解决方案

Statically (i.e. in your layout XML file): set android:inputType="textCapSentences" on your EditText.

Programmatically: you have to include InputType.TYPE_CLASS_TEXT in the InputType of the EditText, e.g.

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

Can be combined with text and its variations to request capitalization of the first character of every sentence.

- Google Docs

这篇关于EditText 的首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:EditText 的首字母大写

基础教程推荐