简体   繁体   English

带数字键盘的EditText,但允许字母数字值

[英]EditText with numeric keyboard but allowing alphanumeric values

Problem: 问题:

  • my own class which extends EditTextPreference 我自己的类,扩展了EditTextPreference
  • a method within that class called " setInputType() " with this.getEditText().setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED); 该类中的一个方法叫做“ setInputType()this.getEditText().setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);

  • my xml with elements of my own EditText-class with 我的xml具有我自己的EditText-class的元素,具有

    • title, summary, key, defaultValue, digits, nothing else. 标题,摘要,键,defaultValue,数字,仅此而已。
    • android:digits="1234567890"

What i want is: 我想要的是:

  • the default value will always be numeric, but leading zeros have to be possible. 默认值将始终为数字,但是前导零必须是可能的。 so my thought was, that I have to either have a inputtype "phone" or "text", although i dont want letters to be allowed. 所以我的想法是,尽管我不希望允许输入字母,但我必须有一个输入类型“ phone”或“ text”。 as you see 正如你看到的

my problem: 我的问题:

I can type the numbers from 0123456789 , but my edittext opens with the normal keyboard. 我可以输入0123456789的数字,但是我的edittext用普通键盘打开。 but when I tried to change it to numeric keyboard, I couldnt manage to make the 0 be allowed. 但是,当我尝试将其更改为数字键盘时,我无法设法将其设置为0。 Is there a clean solution? 有没有干净的解决方案? everything i found is either just making the numeric keyboard as default OR allowing my wanted digits. 我发现的所有内容要么只是将数字键盘设置为默认键盘,要么允许我想要的数字。

Thank you for your help :) 谢谢您的帮助 :)

Change XML's Edit text with simply this :: 只需使用以下::更改XML的编辑文本:

<EditText 
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLength="50"
        android:singleLine="true"
    />

And code as :: 和代码为::

editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL);

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

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