简体   繁体   English

Android软件键盘以编程方式在数字和字母之间切换

[英]Android software keyboard switch between numeric and alphabetic programmatically

I have an EditText with inputMode = text . 我有一个inputText = text的EditText。 By default software keyboard is shown as alphabetical and user have to switch it to numeric by pressing specific key (like "123"). 默认情况下,软件键盘显示为字母,用户必须通过按特定键(例如“ 123”)将其切换为数字。

Having text inputMode is it possible to show numeric keyboard by default instead of alphabetic? 具有文本 inputMode是否可以默认显示数字键盘而不是字母键盘?

I need both alphabetic and numeric. 我需要字母和数字。 But numeric is used more often then alphabetic so i search for way to switch mode programmatically. 但是,与字母相比,数字更常用,因此我寻找以编程方式切换模式的方法。

I find the answer a day, finally I found this and its work. 我每天都找到答案,最后我找到了它及其工作。

android:inputType="textVisiblePassword"

source 资源

Just set it with the normal setter: 只需使用普通的setter进行设置即可:

    EditText editText = (EditText) findViewById(R.id.edittext);
    editText.setInputType(InputType.TYPE_CLASS_NUMBER);
    // or 
    editText.setInputType(InputType.TYPE_CLASS_TEXT);

您可以通过将以下属性设置为xml上的EditText的android:inputType="number"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM