Getting Started

15 Apr 20163 minutes to read

Create your first Barcode in Xamarin.Android Studio

This section explains how to configure a Barcode for Xamarin.Android application by using the Xamarin.Android. To get started with the Essential Barcode, refer to the following steps and in result, you get the output on Android devices as follows.


QR Barcode

Configure the Barcode control

The following steps explain how to create and configure a Barcode.

1.Add reference to the SfBarcode as follows.

2.Create a SfBarcode instance in the Main Activity and set the SfBarcode as a ContentView in onCreate() overridden method.

  • c#
  • public class MainActivity extends Activity {
    
    	@Override
    
    	protected void onCreate(Bundle savedInstanceState) {
    
    		super.onCreate(savedInstanceState);
    
    		// creates new instance for Barcode
    
    		SfBarcode sfBarcode = new SfBarcode(this);
    
    		setContentView(sfBarcode);
    
    	}

    3.Then you can set the text that you want to encode.

  • c#
  • sfBarcode.Text = "http://www.wikipedia.org";

    4.Set the required symbology to encode the given text. By default, the given text is encoded by using Code 39 symbology.

  • c#
  • sfBarcode.Symbology = BarcodeSymbolType.QRBarcode;

    5.To customize the Barcode, initialize the settings of the corresponding Barcode symbology.

  • c#
  • QRBarcodeSettings setting = new QRBarcodeSettings();
        setting.XDimension = 15;
        sfBarcode.SymbologySettings = setting;

    6.Finally, the Barcode is generated as displayed in the screenshot by using the following code example.

  • c#
  • public class MainActivity : Activity
        {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
                SfBarcode sfBarcode = new SfBarcode(this);
                sfBarcode.Text = "http://www.wikipedia.org";
                sfBarcode.Symbology = BarcodeSymbolType.QRBarcode;
                QRBarcodeSettings setting = new QRBarcodeSettings();
                setting.XDimension = 15;
                sfBarcode.SymbologySettings = setting;
                sfBarcode.SetBackgroundColor(Color.White);
                SetContentView(sfBarcode);
            }
        }