在 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作为条码捕获的视图。
您可以根据需要设置该布局的样式。例如,要制作边框,只需在根布局中设置填充。
希望对你有帮助。