深圳全飞鸿
标题:
关于android软键盘的专题研究, softinput
[打印本页]
作者:
zhgc
时间:
2019-11-4 13:11
标题:
关于android软键盘的专题研究, softinput
Activity下所有EditText不弹出软键盘
public void disableShowInput(EditText editText) {
if (android.os.Build.VERSION.SDK_INT <= 10) {
editText.setInputType(InputType.TYPE_NULL);
} else {
Class<EditText> cls = EditText.class;
Method method;
try {
method = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
method.setAccessible(true);
method.invoke(editText, false);
} catch (Exception e) {//TODO: handle exception
}
try {
method = cls.getMethod("setSoftInputShownOnFocus", boolean.class);
method.setAccessible(true);
method.invoke(editText, false);
} catch (Exception e) {//TODO: handle exception
}
}
}
复制代码
@Override
protected void onResume() {
super.onResume();
List<View> list = getAllChildViews(this.getWindow().getDecorView());
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof EditText)
disableShowInput((EditText) list.get(i));
}
}
复制代码
private List<View> getAllChildViews(View view) {
List<View> allchildren = new ArrayList<View>();
if (view instanceof ViewGroup) {
ViewGroup vp = (ViewGroup) view;
for (int i = 0; i < vp.getChildCount(); i++) {
View viewchild = vp.getChildAt(i);
allchildren.add(viewchild);
//再次 调用本身(递归)
allchildren.addAll(getAllChildViews(viewchild));
}
}
return allchildren;
}
复制代码
欢迎光临 深圳全飞鸿 (http://www.nagomes.com/disc/)
Powered by Discuz! X3.2