I want to allow only negative numeric and decimal input with the nice numeric keypad that shows all the numbers in a 3x3 keypad. This keypad has a negative button, but it doesn't do anything, and I can't figure out how to activate it. The following is what I have, but it only allows numeric input:
<EditText
android:id="#+id/expense_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/FieldNumeric"
android:text="0.00"/>
I've seen several answers already that say to add
android:inputType="numberSigned"
or to use
TYPE_NUMBER_FLAG_SIGNED
among other suggestions. The problem with these answers is they lose the nice 3x3 numeric keypad and bring in the alphabetic keyboard.
Any suggestions would be awesome.
Thanks,
Devin
This worked for android 4.2.2 (Jellybean):
android:inputType="numberSigned|numberDecimal"
Related
I have an app that has the following EditText field:
<EditText
android:id="#+id/myEditText"
android:layout_width="0dip"
android:layout_height="match_parent"
android:inputType="numberDecimal|numberSigned"
android:textAlignment="center"
android:enabled="true"
android:text="#{viewModel.whereINeedANegativeNumber}"
android:layout_weight="1" />
What this produces is the following keyboard when a user clicks into the field:
The testers believe it isn't intuitive, and they are correct, to have to double-tap the [ .- ] key in order to enter a negative sign.
What I would like is a keyboard like the following (notice the new location of the decimal and negative sign):
So ... is there a way to remap the keyboard to give the decimal and negative sign their own, independent keys?
There are ~25,000 Android device models. What the input method editor (soft keyboard) will look like will depend on the device model, and in some cases the third-party keyboard that the user installed. Things like inputType provide a hint to the keyboard, but the rendering of the keyboard is up to the developers of the keyboard.
is there a way to remap the keyboard to give the decimal and negative sign their own, independent keys?
No. You seem to have a reasonable inputType value. IMHO, I agree that a numberDecimal|numberSigned EditText should have dedicated keys for the decimal separator and the negative sign. However, that is not up to us, and the behavior will vary by device.
I am looking to implement both phone pad and keypad in Android.As, per my requirement when the EditText is selected a default phone pad should be shown. But the user must be able to input alphabets also. Please suggest me a way to implement this.
<EditText
android:id="#+id/editTextref1"
android:layout_width="210dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:ellipsize="start"
android:hint="#string/custom1"
android:imeOptions="actionNext|actionDone"
android:inputType="text"
android:nextFocusDown="#+id/editTextref2"
android:shadowDy="10"
android:textColor="#383838"
android:textSize="14sp"
android:textStyle="bold"
android:maxLength="15"
android:typeface="serif" />
I would like to make an assumption that it's impossible to do that in a simple and elegant way. The problem is that you input type is InputType.TYPE_CLASS_TEXT and it cannot be changed to InputType.TYPE_CLASS_NUMBER because you need to input letters as well.
The problem is that input method checks the type of input and gives you the appropriate keyboard with numbers or alphabet depending on the type of the field input type. If you ask input method to give you number keyboard and you have your EditText in focus, you cannot force the input method to switch to alphabet keyboard in your code. I may be wrong but this is what I think.
The question is whether you can ask any third party input method to give you different keyboard while editing text - I think you cannot do this in your code. Input method will give you numbers or alphabet depending on your EditText but you cannot switch them dynamically because input method is not aware of your design issues. The only way you can do this is to make your own input method that allows you to switch numeric and alphabet keyboards dynamically.
Let's say I have an EditText and I want to restrict it to 0-9 and A-F (inclusive), for hex input. Is there a way I can do that? I tried looking at InputFilters and I'm not sure that's the right way. Has anyone achieved this?
Set the input type to number and digits to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
In an xml file it would look like this:
<EditText
android:id="#+id/hexedit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:inputType="number"
/>
You can experiment with different inputTypes to see which soft keyboard layout they bring up.
In one of my edittext fields users can enter numeric values and colons. These keys are part of one specific page of the keyboard. I would like to open that specific page if the users enters the corresponding edittext field. If there's a XML attribute for the layout it would be even better.
Many thanks in advance.
To display pure numeric keyboard use android:inputType="phone"
The android:inputType="time" is the best options for time input. It
will let you input numbers and colon ':'.
For 'Known Distance' and 'Distance to estimate' you can use
android:inputType="number|numberDecimal". It will let you input
numbers with dots i.e double or floats.
You can use android:inputType="number" for Numbers. Here is an example of EditText which opens phone with digits-numbers Keyboard.
<EditText
android:id="#+id/test"
android:inputType="phone"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
Here is a small example of using inputType in layout.
You can use following values in inputType field.
none
text
textCapCharacters
textCapWords
textCapSentences
textAutoCorrect
textAutoComplete
textMultiLine
textImeMultiLine
textNoSuggestions
textUri
textEmailAddress
textEmailSubject
textShortMessage
textLongMessage
textPersonName
textPostalAddress
textPassword
textVisiblePassword
textWebEditText
textFilter
textPhonetic
textWebEmailAddress
textWebPassword
number
numberSigned
numberDecimal
numberPassword
phone
datetime
date
time
Here is detailed explanation about it.
According to InputType of EditText in Android and other answers here, the only way is to make your own class of keyboard. Or find some ready on the net.
my question is kinda related to this question: Numeric Soft Keyboard on Android
BUT, the question above isnt answered, so here i am.
Theres a EditText that when it gets touched or has focus, i want the Software Keyboard to show up by default as NUMERIC! Of course, you can switch back to ALPHANUMERIC, but i want to force it to show up as NUMERIC.
Thanks guys
Use the android:inputType XML attribute with the number value:
<EditText android:id="#+id/edtInput"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:inputType="number"/>