【问题标题】:How to change ZXingScannerView default appearance?如何更改 ZXingScannerView 默认外观?
【发布时间】:2019-02-04 10:12:56
【问题描述】:

我正在使用 ZXing 库制作一个简单的条形码阅读器应用程序,但我想自定义条形码阅读器的样式(布局)

我正在使用自动生成布局的 ZXingScannerView,我想给它一个边框并改变它的位置。

  ZXingScannerView scannerView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        scannerView = new ZXingScannerView(this);         
        setContentView(scannerView);
  }
  ...

【问题讨论】:

标签: android barcode zxing


【解决方案1】:

在 github JourneyApps 中查看这个项目。

示例代码有scanBarcodeCustomLayout(View view)方法。

    public void scanBarcodeCustomLayout(View view) {
        IntentIntegrator integrator = new IntentIntegrator(this);
        integrator.setCaptureActivity(AnyOrientationCaptureActivity.class);
        integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
        integrator.setPrompt("Scan something");
        integrator.setOrientationLocked(false);
        integrator.setBeepEnabled(false);
        integrator.initiateScan();
    }

有一条对你很重要的台词

integrator.setCaptureActivity(AnyOrientationCaptureActivity.class);

That AnyOrientationCaptureActivity class 只是从CaptureActivity 扩展而来,没有更多代码。所以,这意味着CaptureActivity 具有条形码视图的默认样式。

package example.zxing;

import com.journeyapps.barcodescanner.CaptureActivity;

/**
 * This Activity is exactly the same as CaptureActivity, but has a different orientation
 * setting in AndroidManifest.xml.
 */
public class AnyOrientationCaptureActivity extends CaptureActivity {

}

现在看看

setContentView(R.layout.zxing_capture);

您需要做的就是创建自己的类。从CaptureActivity 复制所有代码,并将您的custom xml layout 设置为setContentView()

然后附上com.journeyapps.barcodescanner.DecoratedBarcodeView作为条码捕获的视图。

您可以根据需要设置该布局的样式。例如,要制作边框,只需在根布局中设置填充。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-30
    • 2014-09-10
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多