EditText view with keyboard number only

2020-01-30 22:38发布

I want a keyboard with ONLY visible numbers to an EditText view. Without any other character.

I have tested with all available inputs and don't work. I have searched a way to get a keyboard only with numbers but I have only seen references to:

android: inputType = "numberPassword"

But I want visible numbers in EditText. Someone can help me?

I want a keyboard like that: (numberPassword)

enter image description here

I have tried with:

android:digits="0123456789"
android:inputType="phone"

and

android:inputType="number"

and appears like that:

enter image description here

8条回答
冷血范
2楼-- · 2020-01-30 23:10

In xml edittext:

android:id="@+id/text"

In program:

EditText text=(EditText) findViewById(R.id.text);
text.setRawInputType(Configuration.KEYBOARDHIDDEN_YES);
查看更多
Juvenile、少年°
3楼-- · 2020-01-30 23:11

I think you used somehow the right way to show the number only on the keyboard so better try the given line with xml in your edit text and it will work perfectly so here the code is-

  android:inputType="number"

In case any doubt you can again ask to me i'll try to completely sort out your problem. Thanks

查看更多
Root(大扎)
4楼-- · 2020-01-30 23:11

For the EditText if we specify,

android:inputType="number"

only numbers can be got. But if you use,

android:inputType="phone"

along with the numbers it can accept special characters like ;,/". etc.

查看更多
该账号已被封号
5楼-- · 2020-01-30 23:12

Place the below lines in your <EditText>:

android:digits="0123456789"
android:inputType="phone"
查看更多
Lonely孤独者°
6楼-- · 2020-01-30 23:19

After several tries, I got it! I'm setting the keyboard values programmatically like that

 myEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); 

Or if you want you go with the XML view is like:

android: inputType = "numberPassword"

Both configs gonna display a password bullets, and as far as we are looking display numbers on the EditText we need to create a custom ClickableSpan class.

 private class NumericKeyBoardTransformationMethod extends PasswordTransformationMethod {
    @Override
    public CharSequence getTransformation(CharSequence source, View view) {
        return source;
    }
}

And finally we need implementing it to the EditText in order to display the characters typed.

myEditText.setTransformationMethod(new NumericKeyBoardTransformationMethod());

This is how my keyboard looks like now

查看更多
家丑人穷心不美
7楼-- · 2020-01-30 23:25
<EditText
        android:id="@+id/editText3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ems="10"
        android:inputType="number" />

I have tried every thing now try this one it shows other characters but you cant enter in the editText

edit.setRawInputType(Configuration.KEYBOARD_12KEY);

enter image description here

查看更多
登录 后发表回答