zoukankan      html  css  js  c++  java
  • android 模拟输入框edittext控件按下回车或扫描头扫描到条码

    edtScan.setText(result); 
    edtScan.onEditorAction(EditorInfo.IME_ACTION_NEXT);

    场景:PDA都有扫描头,但有时想用自己的手机来扫码。于是给项目添加了相机使用Zbar识别二维码和条码的功能,
    现在扫描头扫描到二维码或条码时是在PDA的扫描设置里加后缀(回车+换行)来实现输入框焦点跳转触发的。
    相机识别二维码后需要模拟扫描头的扫描动作。不需要加回车换行,亲试无用,发现使用EditorInfo.IME_ACTION_NEXT,让输入框切换到下一个焦点即可。
     edtScan.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId,
                                              KeyEvent event) {
                    String scanertext = edtScan.getText().toString();
                    if (scanertext.contains("-") && scanertext.length() > 3) {
                        edtScan.setText("");
                        RefreshWebView(scanertext);
                    } else if (scanertext.length() > 0) {
                        edtScan.setText("");
                        String msg = "编码规则不符,请扫描位置二维码!";
                        Toast.makeText(HtmlViewActivity.this, msg,
                                Toast.LENGTH_SHORT).show();
                        MainActivity.getInstance().SpeakVoice(msg);
                        String head = "<head>"
                                + "<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> "
                                + "<style>html{padding:15px;} body{word-wrap:break-word;font-size:13px;padding:0px;margin:0px} p{padding:0px;margin:0px;font-size:13px;color:#222222;line-height:1.3;} img{padding:0px,margin:0px;max-100%; auto; height:auto;}</style>"
                                + "</head>";
                        webview.loadData("<html>" + head + "<body>"
                                        + " <h1>请扫描位置二维码!eg:A-R1:C1</h1> " + "</body></html>",
                                "text/html;charset=utf-8", "utf-8");
                    }
                    return true;
                }
            });
        }
    
    
    



  • 相关阅读:
    AngularJs $http.post 数据后台获取不到数据问题 的解决过程
    网络安全学习和CTF必不可少的一些网站
    汇编语言学习资料汇总
    链表的归并排序
    数学常用模板——矩阵 高精度
    Gym100810J Journey to the "The World's Start" (二分答案+动态规划)
    图论:最短路
    Codeforces Round #642 (Div. 3)补题
    离散数学真值表的计算
    【C/C++】字典树
  • 原文地址:https://www.cnblogs.com/datacool/p/11787211.html
Copyright © 2011-2022 走看看