Bar Code Scanner in Android with Custom Layout (ZXing)

Very short guide on how to add bar code scanner with a customized layout to the app you write using Android Studio.

Marta Pyznarska
2 min readJun 30, 2014

[EDIT — June 2015] The library for integrating zxing was hugely updated recently, and now, it should be much more convinient to crate custom activities with custom layouts, according to its authors. So probably you should first check out this. I haven’t tested it personally, though.

IF ABOVE DOESN’T WORK FOR YOU THIS IS MY SOLUTION FROM ~MAY 2014

There are few barcode image processing libraries with clients for Android out there. I chose Zxing. Then I struggled how to nicly embed it to my project in Android Studio. To my rescue came zxing-android-minimal on Github.

But there was one pitfall. I needed to have my own layout of the camera scan screen. And I also needed to have a button on this layout that would stand as a ‘Cancel’ button.

Adding just few lines of code to the library solved the problem: https://github.com/embarkmobile/zxing-android-minimal/pull/10. The very same day I did the pull request, guys from embarkmobile merged the changes and pushed updated Maven artefact.

Github is amazing.

So now

  1. Add required AAR dependencies in Gradle (https://github.com/embarkmobile/zxing-android-minimal#adding-aar-dependency-with-gradle)
  2. Provide a custom layout for the capture activity. See sample/src/main/res/layout/custom_capture_layout.xml for examples.
  3. Set up the Scanner in your Java code:
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setCaptureLayout(R.layout.custom_layout);
integrator.initiateScan();

For a cancel/back button, use the ids @id/zxing_back_button for zxing-android-minimal.

https://github.com/embarkmobile/zxing-android-minimal#custom-layout

--

--