gpt4 book ai didi

android - 如何更改 ZXingScannerView 默认外观?

转载 作者:行者123 更新时间:2023-11-30 05:06:24 25 4
gpt4 key购买 nike

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

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

  ZXingScannerView scannerView;

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

最佳答案

在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 类 只是从 CaptureActivity 扩展而来,没有更多的代码。所以,这意味着 CaptureActivity 具有条形码 View 的默认样式。

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 中的所有代码,并在 setContentView() 中设置您的自定义 xml 布局

然后附加com.journeyapps.barcodescanner.DecoratedBarcodeView作为条码捕获的 View 。

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

希望对你有所帮助

关于android - 如何更改 ZXingScannerView 默认外观?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54513936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com