I want my EditText
to display a keyboard that ONLY has numbers visible, no other characters.
I have tested with all available inputs and it doesn't work. I searched for a way to get a keyboard that only has numbers but I have only seen references to:
android: inputType = "numberPassword"
But I want the numbers to be visible, like this: (numberPassword)
I have tried with:
android:digits="0123456789"
android:inputType="phone"
and
android:inputType="number"
but it appears like this:
This question is related to
android
android-layout
android-edittext
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
android:inputType="number"
or android:inputType="phone"
. You can keep this. You will get the keyboard containing numbers. For further details on different types of keyboard, check this link.
I think it is possible only if you create your own soft keyboard. Or try this android:inputType="number|textVisiblePassword
. But it still shows other characters. Besides you can keep android:digits="0123456789"
to allow only numbers in your edittext
. Or if you still want the same as in image, try combining two or more features with | separator and check your luck, but as per my knowledge you have to create your own keypad to get exactly like that..
In xml edittext
:
android:id="@+id/text"
In program:
EditText text=(EditText) findViewById(R.id.text);
text.setRawInputType(Configuration.KEYBOARDHIDDEN_YES);
If you want to show just numbers without characters, put this line of code inside your XML file android:inputType="number"
. The output:
If you want to show a number keyboard that also shows characters, put android:inputType="phone"
on your XML. The output (with characters):
And if you want to show a number keyboard that masks your input just like a password, put android:inputType="numberpassword"
. The output:
I'm really sorry if I only post the links of the screenshot, I want to do research on how to do really post images here but it might consume my time so here it is. I hope my post can help other people. Yes, my answer is duplicate with other answers posted here but to save other people's time that they might need to run their code before seeing the output, my post might save you some time.
Place the below lines in your <EditText>
:
android:digits="0123456789"
android:inputType="phone"
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.
<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);
Source: Stackoverflow.com