How to set InputType to InputType.TYPE_CLASS_NUMBER in Android version 7.0 (nougat) and higher

I created a Custom Edittext in which I set InputType as this.setInputType(InputType.TYPE_CLASS_NUMBER); but the problem is that it works fine at a level below 7.0 (nougat), but above 7.0 it shows me an alphanumeric keyboard.

Another strange event happened: when I touch EditText, I quickly get a soft numeric keypad, but in less than a second it automatically switches to a regular soft keyboard that displays all the letters. also, when the keyboard is open, and not the back button, than closing the keyboard, but when I again went into Edittext. the keyboard is not open until I click onther edittext and then the current edittext

Is this a problem in Nougat or am I doing something wrong

For information, I used the code for setSoftInputMode for ADJUST PAN

 setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN |WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

and to set the numeric keypad, use this.setInputType(InputType.TYPE_CLASS_NUMBER);

Edited - when I delete -

 setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN |WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

everything works fine from activity (the keyboard number opens with the edittext number, the alphanumeric keyboard opens in the alphanumeric editor), except that the content does not go up, it means that the keyboard is hidden with edittext (because ignorance of this property is SOFT_INPUT_ADJUST_PAN)

Help with thanks

+5
source share
2 answers

I tried using setInputType (InputType.TYPE_CLASS_NUMBER) on 7+ devices and did not see the behavior you described. Looking for another thread, runnable, or any callback that changes the InputType of your EditText after opening or at the same time.

+3
source

Try installing softInputMode in your Manifest file, this may give you the desired behavior.

 <activity android:name=".YourActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustPan|stateAlwaysHidden" /> 
0
source

Source: https://habr.com/ru/post/1271728/


All Articles