zoukankan      html  css  js  c++  java
  • android 使EditText始终不弹出软键盘,并且有光标

    今天做一个功能,PDA扫描条码内容显示到文本框,但点击EditText时老是弹出软键盘,挡住了一些信息,体验很不好,网上找了很久终于找到最佳效果,参考https://blog.csdn.net/suowolegeca/article/details/49128939

    很多说直接设置et_emulator_qrcord.setInputType(InputType.TYPE_NULL); 确实不弹出软键盘,但是不显示光标,最重要是扫描条码也取不到数据,最终使用以下方法完美解决。

     // 获取文本框
      et_emulator_qrcord = (EditText) findViewById(R.id.et_emulator_qrcord);
      //禁止弹出软键盘,并且有光标
      if (android.os.Build.VERSION.SDK_INT <= 10) {
          et_emulator_qrcord.setInputType(InputType.TYPE_NULL);
       } else {
          getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
          try {
          //采用反射的方式,调用系统内部方法
             Class<EditText> cls = EditText.class;
             Method setSoftInputShownOnFocus;
             setSoftInputShownOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
             setSoftInputShownOnFocus.setAccessible(true);
             setSoftInputShownOnFocus.invoke(et_emulator_qrcord, false);
           } catch (Exception e) {
             e.printStackTrace();
           }
       }
  • 相关阅读:
    windows下python开发环境搭建
    看看两年前的我
    网络函数[00]函数总述
    网络函数[04]connect解析
    网络函数[08]网络读取函数解析
    网络函数[01]套接口地址图解
    网络函数[13]
    网络函数[07]accept解析
    网络函数[10]shutdown解析
    网络函数[14]
  • 原文地址:https://www.cnblogs.com/Mrshuang11/p/13949783.html
Copyright © 2011-2022 走看看