深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 607|回复: 0
打印 上一主题 下一主题

关于android软键盘的专题研究, softinput

[复制链接]

800

主题

1379

帖子

7725

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7725
跳转到指定楼层
楼主
发表于 2019-11-4 13:11:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Activity下所有EditText不弹出软键盘

  1.     public void disableShowInput(EditText editText) {
  2.         if (android.os.Build.VERSION.SDK_INT <= 10) {
  3.             editText.setInputType(InputType.TYPE_NULL);
  4.         } else {
  5.             Class<EditText> cls = EditText.class;
  6.             Method method;
  7.             try {
  8.                 method = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
  9.                 method.setAccessible(true);
  10.                 method.invoke(editText, false);
  11.             } catch (Exception e) {//TODO: handle exception
  12.             }
  13.             try {
  14.                 method = cls.getMethod("setSoftInputShownOnFocus", boolean.class);
  15.                 method.setAccessible(true);
  16.                 method.invoke(editText, false);
  17.             } catch (Exception e) {//TODO: handle exception
  18.             }
  19.         }
  20.     }
复制代码

  1.     @Override
  2.     protected void onResume() {
  3.         super.onResume();
  4.         List<View> list = getAllChildViews(this.getWindow().getDecorView());
  5.         for (int i = 0; i < list.size(); i++) {
  6.             if (list.get(i) instanceof EditText)
  7.                 disableShowInput((EditText) list.get(i));
  8.         }
  9.     }
复制代码

  1.     private List<View> getAllChildViews(View view) {
  2.         List<View> allchildren = new ArrayList<View>();
  3.         if (view instanceof ViewGroup) {
  4.             ViewGroup vp = (ViewGroup) view;
  5.             for (int i = 0; i < vp.getChildCount(); i++) {
  6.                 View viewchild = vp.getChildAt(i);
  7.                 allchildren.add(viewchild);
  8.                 //再次 调用本身(递归)
  9.                 allchildren.addAll(getAllChildViews(viewchild));
  10.             }
  11.         }
  12.         return allchildren;
  13.     }
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-6-29 13:59 , Processed in 0.050141 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表