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;
                }
            });
        }
    
    
    



  • 相关阅读:
    专家教你应对小孩鼻血不止
    爸爸去哪?
    Windows server 2008 R2 + IIS7.5,ASP网站设置
    请把这十个生命气质传给孩子
    zoj 2071 Technology Trader 最大权闭合子图
    TJU 2944 Mussy Paper 最大权闭合子图
    poj 1222 EXTENDED LIGHTS OUT 高斯消元
    codeforces 383C Propagating tree 线段树
    ubuntu 安装qq
    Kafka Manager 监控
  • 原文地址:https://www.cnblogs.com/datacool/p/11787211.html
Copyright © 2011-2022 走看看