简体   繁体   English

如何在Android版本7.0(牛轧糖)及以上版本中将InputType设置为InputType.TYPE_CLASS_NUMBER

[英]how to set InputType to InputType.TYPE_CLASS_NUMBER in Android Version 7.0 (nougat) and above

I have created Custom Edittext in which i set the InputType as this.setInputType(InputType.TYPE_CLASS_NUMBER); 我创建了自定义Edittext,其中我将InputType设置为this.setInputType(InputType.TYPE_CLASS_NUMBER); but the problem is it working perfectly on below 7.0(nougat) but above 7.0 it show me alphanumeric keyboard. 但问题是它在7.0(牛轧糖)以下完美运行但在7.0以上它显示了字母数字键盘。

one another weird thing happen is when I touch the EditText, I quickly get the soft numerical keyboard, but in less than a second it automatically changes to regular soft keyboard showing all letters. 另一个奇怪的事情发生在我触摸EditText时,我很快就得到了软数字键盘,但在不到一秒的时间内,它会自动变为显示所有字母的常规软键盘。 also when keyboard is open, than ill press back button, than keyboard close, but when i re-enter in Edittext. 当键盘打开时,比按下后退按钮,比键盘关闭,但当我重新输入Edittext时。 keyboard is not open until i click on onther edittext then current edittext 直到我点击onther edittext然后当前的edittext才打开键盘

Is this issue in Nougat or I am doing something wrong 这是Nougat的问题还是我做错了什么

For information i have used code to setSoftInputMode to ADJUST PAN 有关信息,我已使用代码将setSoftInputMode设置为ADJUST PAN

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

and to set Numeric keypad use this.setInputType(InputType.TYPE_CLASS_NUMBER); 并设置数字小键盘使用this.setInputType(InputType.TYPE_CLASS_NUMBER);

Edited - when i remove - 编辑 -当我删除 -

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

from activity every thing work fine( number keypad open at number edittext , alphanumerical keypad open at alphanumerical edittext ) except the content not goes up-direction means keypad hide edittext(because ignorance of this property SOFT_INPUT_ADJUST_PAN) 从活动每件事工作正常(数字键盘打开数字edittext,字母数字键盘打开alphanumerical edittext)除了内容没有向上方向意味着键盘隐藏edittext(因为无知这个属性SOFT_INPUT_ADJUST_PAN)

Help appreciated thanks 感谢谢谢

I tried to use setInputType(InputType.TYPE_CLASS_NUMBER) on devices 7+ and didn't see the behaviour that you described. 我尝试在设备7+上使用setInputType(InputType.TYPE_CLASS_NUMBER),但没有看到您描述的行为。 Looking for another thread, runnable or any callback which changing InputType of your EditText after opening or simultaneously. 寻找另一个线程,runnable或任何在打开或同时更改EditText的InputType的回调。

Try setting softInputMode in your Manifest file, it might give you your desired behavior. 尝试在Manifest文件中设置softInputMode ,它可能会为您提供所需的行为。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM