可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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)
I have tried with:
android:digits="0123456789"
android:inputType="phone"
and
android:inputType="number"
and appears like that:
回答1:
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
回答2:
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..
回答3:
<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);
回答4:
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
回答5:
Place the below lines in your <EditText>
:
android:digits="0123456789"
android:inputType="phone"
回答6:
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.
回答7:
In xml edittext
:
android:id="@+id/text"
In program:
EditText text=(EditText) findViewById(R.id.text);
text.setRawInputType(Configuration.KEYBOARDHIDDEN_YES);
回答8:
If you want to show just numbers without characters, put this line of code inside your xml file android:inputType="number"
. Below image shows the exact output
enter image description here
If you want to show a number keyboard which also shows characters, put android:inputType="phone"
on your xml. Below shows the exact output.
with characters
And if you want to show a number keyboard that masks your input just like a password, put android:inputType="numberpassword"
. Below is the output.
enter image description here
I'm really sorry if I only post the links of the screenshot, I want to do a 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. Have a nice day everyone!