2

I have certain number of edittexts in my activity and I specified each edittext with input type :"number" In order to show the keyboard only with numbers. when I click on the edittext initially it shows the keyboard with number after a fraction of second it changed to text keyboard.so I cannot types numbers directly.

Even though I've given android:windowSoftInputMode="stateHidden" this to my activity. I don't know the reason why it is changed like that,

<EditText
  android:id="@+id/editText1"
  android:layout_width="200dp"
  android:layout_height="wrap_content"
  android:textColor="@color/black"
  android:textSize="30dp"
  android:layout_weight="25"
  android:textAlignment="center"
  android:gravity="center_horizontal"
  android:inputType="numberDecimal"
       />

Thank you All for given response to my question I rectified the problem, when I removed these lines"android:textColor="@color/black" android:textSize="30dp" android:textAlignment="center" from my code keyboard worked properly Once again thank you All

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
lakshmi
  • 21
  • 3
  • 9

5 Answers5

3

I had a same problem. Use in build.gradle: implementation 'androidx.appcompat:appcompat:1.3.1' instead of implementation 'androidx.appcompat:appcompat:1.4.0' and android:inputType="number" will work.

mcasdf
  • 43
  • 6
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 12 '21 at 00:57
1

Change to

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

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.

refer this https://developer.android.com/reference/android/widget/TextView.html#attr_android:digits

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
1

Use "number" format :

android:inputType="number"

or Define the set you want to use (If using this avoid using inputType):

android:digits="0123456789"
W4R10CK
  • 5,502
  • 2
  • 19
  • 30
0

You can use digits in your EditText like this to get input from keyboard only with numbers

android:digits="0123456789"

Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60
0

You can use like this, (if you need dot and comma) otherwise remove it..

 <EditText
        android:inputType="number"
        android:digits="0123456789.," />
Mujammil Ahamed
  • 1,454
  • 4
  • 24
  • 50