Android EditText InputType相关——if(dosen't work)小心你的输入法
来源:互联网 发布:naca翼型实验数据 编辑:程序博客网 时间:2024/06/08 09:02
今天在对一个proj输入做些许修改的时候,因为要对EditText输入进行规范,所以查了下API,找到了inputType属性可以对EditText的输入进行规范,所以就很开心地用了。这里简单介绍一下inputType属性所接收的各属性值、作用以及使用方法。
1、在xml中使用
在xml中使用,只需要简单地指定android:inputType的属性值就可以了。比较常用的属性值有:
"textCapSentences" 大写句子句首字母
"textCapWords" 大写每个单词开头字母
"textAutoCorrect" 自动纠正不正确拼写
"textMultiLine" 允许多行输入
一个例子:
<EditText android:id="@+id/postal_address" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/postal_address_hint" android:inputType="textPostalAddress| textCapWords| textNoSuggestions" />
2、在Java代码中设置
在代码中设置的方法其实和xml中的实现完全类似,直接举个例子:
EditText testEditText = (EditText) findViewById(R.id.test_editText); testEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Voilà!然后在如此设置好后,在机子上一跑,2了,什么反应都没有...于是我就郁闷了,双管齐下,在xml和代码中分别设置,还是doesn't work。于是就最后一招stackoverflow了...发现在stackoverflow上,相关的capitalize问题回答都是设置inputType相关的属性。有些回答在追问中,详细描述了平台和系统版本,都说就这样能实现需求。看到这里我就郁闷了,因为我的还是没有任何效果。然后这时候进来一条同学的短信,开始回短信的时候切换成英文输入,突然想到,老外都是直接输拉丁字母的,回答者都说这样就可以实现需求,是不是要用系统自带的输入法?lz本来使用的是百度输入法,当然我觉得百度中文输入还是很不错的,字母按钮够大,表情标点什么的也插入方便。有这样的想法后就马上去切换到了系统自带的输入法,发现,嗯,真的可以了。
接下来就是忍痛删了百度输入法,下了个googel拼音,虽然我觉得google拼音很好,但是有点小的字母按钮,让我这种指头不敏感人士,有点像母猪弹钢琴的感觉...
thus,马上写篇博客分享一下,给自己和大家一个小tip.
good good study, day day up:)
- Android EditText InputType相关——if(dosen't work)小心你的输入法
- Android 的 EditText inputtype
- android EditText的inputtype
- Android 的EditText的inputtype
- Android-EditText InputType的含义
- EditText的android:inputType属性
- [Android] EditText 的 inputType属性
- Android edittext的inputType属性
- EditText inputType相关设置
- android EditText中inputType的属性列表
- android EditText中inputType的属性列表
- android EditText中inputType的属性列表
- android EditText中inputType的属性列表
- android EditText中inputType的属性列表
- Android中EditText的inputType属性值
- [Android] EditText 的 inputType属性(键盘类型)
- EditText中android:inputType属性的作用
- android EditText中inputType的属性列表
- 补码、模及数据截断
- POJ1782:Run Length Encoding
- 中文乱码解决
- gets()
- 15所名校计算机专业之特色分析
- Android EditText InputType相关——if(dosen't work)小心你的输入法
- 制作日历——04
- puts()
- 使用TELNET命令测试邮箱
- 初学单选框RadioButton和复选框CheckBox
- Java中的随机数
- windows7 64位使用U盘进行系统安装
- scanf()
- webservice(一)入门