lakshmi
lakshmi

Reputation: 21

Input type is not working properly

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

Upvotes: 2

Views: 7853

Answers (5)

mcasdf
mcasdf

Reputation: 43

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.

Upvotes: 3

Amit Vaghela
Amit Vaghela

Reputation: 22955

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

Upvotes: 1

W4R10CK
W4R10CK

Reputation: 5550

Use "number" format :

android:inputType="number"

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

android:digits="0123456789"

Upvotes: 1

Mujammil Ahamed
Mujammil Ahamed

Reputation: 1494

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

 <EditText
        android:inputType="number"
        android:digits="0123456789.," />

Upvotes: 0

Rahul Khurana
Rahul Khurana

Reputation: 8844

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

android:digits="0123456789"

Upvotes: 0

Related Questions