Android Bar Code/ QR-Code Generator Tutorial Using ZXING Library

This tutorial explains how to generate Bar Code or QR-Code in Android device using ZXING Library.


Quick Response(QR) code is a two dimensional barcode(matrix codes) that allows content to be decoded at a high speed. The use of QR code is license-free. This tutorial explains how to implement ZXING library to generate dynamic barcodes into Android applications. We will generate Bar Code into a Image Format.


Create a new project

To generate Bar Code, we are going to create a new android project. Go to File ⇒ New ⇒ New Projects in Android studio. 

Add ZXING library

We need to add ZXING library in our project, so open build.gradle(Module:app) file and add following code:

    url ""

  compile 'com.github.kenglxn.QRGen:android:2.2.0' 


Create Layout

We need to add Imageview tag in the layout. We will generate Bar Code as Image format and Imgaeview is used to display bar code.

<ImageView android:layout_width="match_parent" 


Create a simple Bar Code/QR-Code

To get QR-Code from text use the following code:

Bitmap myBitmap=QRCode.from("").bitmap();


Display Bar Code

To display bar code, initialize the Imageview and Pass bitmap into setImageBitmap() As a parameter.

ImageView myImage=(ImageView) findViewById(;


Generate Bar code with set of details

If we want to generate Bar Code with some details then we need to use VCard object to set details.

VCard abhay=new VCard("Abhay")
Bitmap myBitmap=QRCode.from(abhay).bitmap();


Change Color of Bar code

To change color, we need to pass background color and code color into .withColor()

Bitmap myBitmap=QRCode.from(abhay)
     .withColor(0xFFFF0000, 0xFFFFFFAA).bitmap();



About Abhay Anand

Abhay Anand has experience in the field of Software Development. He can program Android, PHP, JavaScript, Html, Css. He develops web and Android applications. You can reach him at
  • vishnu kumar

    Great tutorial, thanks