How do I default to numeric keyboard on EditText without forcing numeric input?
Add the following line of code, and it will do the trick :)
editText.setRawInputType(Configuration.KEYBOARD_QWERTY);
This will show the the numeric keypad first, but also allows you to enter free text.
More information here.
Open a numeric keyboard without forcing the EditText to be numeric only
Not sure if this is the best solution, but I use android:inputType="phone"
.
Android EditText force numeric keyboard but allow non-numeric chars
This will keep it numeric but will allow the $ character, add any other special chars you need to the android:digits
attribute
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:digits="0123456789,$">
How do you set the EditText keyboard to only consist of numbers on Android?
After several tries, I got it!
I'm setting the keyboard values programmatically like this:
myEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
Or if you want you can edit the XML like so:
android: inputType = "numberPassword"
Both configs will display password bullets, so we need to create a custom ClickableSpan
class:
private class NumericKeyBoardTransformationMethod extends PasswordTransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return source;
}
}
Finally we need to implement it on the EditText
in order to display the characters typed.
myEditText.setTransformationMethod(new NumericKeyBoardTransformationMethod());
This is how my keyboard looks like now:
TextInputEditText to show numeric keyboard but also allow /
Removing android:inputType
and android:digits
from the xml and also adding the below to the activity's onCreate()
seems to do the trick.
input.setKeyListener(DigitsKeyListener.getInstance("0123456789./"));
However it's not completely clear to me that this should or will always work - see note below from the docs on DigitsKeyListener
...
As for all implementations of KeyListener, this class is only concerned with hardware keyboards. Software input methods have no obligation to trigger the methods in this class.
Source: https://developer.android.com/reference/android/text/method/DigitsKeyListener
Related Topics
List View Items Changes Position When Scrolling Android
Broadcastreceiver for Location
Android: Detect Orientation Changed
Tasksnapshot.Getdownloadurl() Is Deprecated
How to Keep a Countdowntimer Running Even If the App Is Closed
Unable to Execute Adb in Ubuntu. Downloaded File Is Meant for X86-64 While I Have I686
Android -- How to Position View Off-Screen
Making a Https Request Using Android Volley
Monitor Network Activity in Android Phones
How to Use Front and Back Camera at Same Time in Android
How to Save Image in Shared Preference in Android | Shared Preference Issue in Android with Image
Using Camera in the Android Emulator
Android Datepicker Min Max Date Before API Level 11
Scan Android Sd Card for New Files
Android How to Replace the Deprecated Tabhost