首先在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
}
}
}