欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

android imeOptions的用法及注意事项

来源: 开发者 投稿于  被查看 31608 次 评论:220

android imeOptions的用法及注意事项


我们在android开发中,必不可少的会使用到文本框(EditText)来进行数据录入,也就会需要对输入法进行一些控制。
android:inputType :指定输入法的类型,int类型,可以用|选择多个。取值可以参考:android.text.InputType类。
取值包括 text, textUri, phone,number,等。
android:imeOptions :指定输入法窗口中的回车键的功能,可选值为normal,actionUnspecified,actionNone,actionGo,actionSearch,actionSend,actionNext,actionDone。

部分输入法对此的支持可能不够好。

 

[html]  
  1. 下面的LAYOUT定义文件举了一些例子说明inputType和imeOptions的使用。
  2. android:layout_width=fill_parent android:layout_height=wrap_content
  3.  
  4. android:hint=Normal text
  5.  
  6. android:inputType=text
  7.  
  8. android:imeOptions=actionNext
  9. />
  10. android:layout_width=fill_parent android:layout_height=wrap_content
  11.  
  12. android:hint=Integer only
  13.  
  14. android:inputType=number
  15.  
  16. android:imeOptions=actionNext
  17. />
  18. android:layout_width=fill_parent android:layout_height=wrap_content
  19.  
  20. android:hint=Decimal only
  21.  
  22. android:inputType=numberDecimal
  23.  
  24. android:imeOptions=actionNext
  25. />
  26. android:layout_width=fill_parent android:layout_height=wrap_content
  27.  
  28. android:hint=Phone number
  29.  
  30. android:inputType=phone
  31.  
  32. android:imeOptions=actionNext
  33. />
  34. android:layout_width=fill_parent android:layout_height=wrap_content
  35.  
  36. android:hint=Email
  37.  
  38. android:inputType=textEmailAddress
  39.  
  40. android:imeOptions=actionSend
  41. />
  42. android:layout_width=fill_parent android:layout_height=wrap_content
  43.  
  44. android:hint=Web Site
  45.  
  46. android:inputType=textUri
  47.  
  48. android:imeOptions=actionDone/>
  49. 随着inputType的不同,输入法的键盘也自动跟着发生变化,并且在inputType=number时,是不允许输入英文字符的。
  50. 注意:android:phoneNumber,android:numeric,这几个属性均已被废弃,不少输入法已经不再支持。直接使用inputType比较好。另外,在做这种调试时,最好使用Google拼音,或android键盘来进行,否则imeOptions可能不能正常显示,比如百度输入法在我删除它之前就一直不支持imeOptions。

用户评论