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下载
    vue-element-admin改造步骤
    js处理url
    好用的工具
    数据库设计工具
    虚拟机使用
    Mac上编译C
    MAC系统配置
    SQL语法
    SSMP一次请求数据处理过程分析
  • 原文地址:https://www.cnblogs.com/datacool/p/11787211.html
Copyright © 2011-2022 走看看