首先在manifest中配置android:windowSoftInputMode="stateHidden|stateUnchanged"让软键盘首次不弹出
然后在介入一下代码
注;etNumber为布局中的EditText...
public void disableShowSoftInput(){
if (android.os.Build.VERSION.SDK_INT <= 10)
{
etNumber.setInputType(InputType.TYPE_NULL);
}
else {
Class<EditText> cls = EditText.class;
Method method;
try {
method = cls.getMethod("setShowSoftInputOnFocus",boolean.class);
method.setAccessible(true);
method.invoke(etNumber, false);
}catch (Exception e) {
// TODO: handle exception
}
try {
method = cls.getMethod("setSoftInputShownOnFocus",boolean.class);
method.setAccessible(true);
method.invoke(etNumber, false);
}catch (Exception e) {
// TODO: handle exception
}
}
}
然后在介入一下代码
注;etNumber为布局中的EditText...
public void disableShowSoftInput(){
if (android.os.Build.VERSION.SDK_INT <= 10)
{
etNumber.setInputType(InputType.TYPE_NULL);
}
else {
Class<EditText> cls = EditText.class;
Method method;
try {
method = cls.getMethod("setShowSoftInputOnFocus",boolean.class);
method.setAccessible(true);
method.invoke(etNumber, false);
}catch (Exception e) {
// TODO: handle exception
}
try {
method = cls.getMethod("setSoftInputShownOnFocus",boolean.class);
method.setAccessible(true);
method.invoke(etNumber, false);
}catch (Exception e) {
// TODO: handle exception
}
}
}
本文介绍如何通过在Android应用中配置manifest文件及使用Java代码来禁用软键盘首次打开应用程序时自动弹出的功能。
2061

被折叠的 条评论
为什么被折叠?



