Android二维码生成功能

调用系统相册扫描返回一个rusult,然后通过输入文字实现二维码生成的功能。

第一步下载一个zxing第三方包 

  然后初始化控件

activity_main.xml

布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >


    <Button
        android:id="@+id/btn_scan_barcode"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:text="Open camera"
        android:onClick="scanner" />
    
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_marginTop="10dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        
        <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:textSize="18sp"
        android:text="Scan result:" />
        
        <TextView 
        android:id="@+id/tv_scan_result"
        android:layout_width="fill_parent"
        android:textSize="18sp"
        android:textColor="@android:color/black"
        android:layout_height="wrap_content" />
    </LinearLayout>
    
    <EditText 
        android:id="@+id/et_qr_string"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:hint="Input the text"/>
    
    <Button
        android:id="@+id/btn_add_qrcode"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Generate QRcode"
        android:onClick="make" />
    
    <ImageView 
        android:id="@+id/iv_qr_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_gravity="center"
        android:background="@drawable/weixin_logo"/>


</LinearLayout>

第二步调用系统相机实现扫描二维码并返回Reuslt


camera.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


    <SurfaceView
        android:id="@+id/preview_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />


    <com.zxing.view.ViewfinderView
        android:id="@+id/viewfinder_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:orientation="vertical" >


        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:background="@drawable/navbar"
            android:gravity="center"
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:text="Scan Barcode"
            android:textColor="@android:color/white"
            android:textSize="18sp"
            android:textStyle="bold" />


        <Button
            android:id="@+id/btn_cancel_scan"
            android:layout_width="230dp"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_centerInParent="true"
            android:layout_marginBottom="75dp"
            android:text="Cancel"
            android:textSize="15sp"
            android:textStyle="bold" />


        <!-- <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="vertical" >


            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="2dp"
                android:gravity="center"
                android:text="@string/scan_prompt_info"
                android:textColor="@android:color/white"
                android:textSize="15sp"
                android:textStyle="bold" />
        </LinearLayout> -->
        
    </RelativeLayout>


</FrameLayout>

第三步实现输入文本点击返回一个Bitmap对象,然后将ImageView设置到Bitmap里面,然后二维码显示出来了。当然你还可以加背景图片,总而言之实现起来还是比较方便!

最后实现效果如下


  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
### 回答1: Android二维码生成库是一种在Android平台上使用的软件开发包,它提供了一套简单而有效的方法来生成二维码Android二维码生成库具有以下优点: 首先,它提供了丰富的功能和选项,使得开发者可以自定义生成的二维码。开发者可以设置二维码的大小、颜色、背景、图像等属性。同时,还可以添加Logo、文字、链接等附加信息,使生成的二维码更加个性化。 其次,它具有良好的兼容性。Android二维码生成库可以在各种Android设备和各个版本上使用,并且与其他Android开发库和框架完美集成。无论是在智能手机、平板电脑还是其他Android设备上,都可以轻松生成高质量的二维码。 此外,Android二维码生成库还具有高性能和稳定性。它经过了严格的测试和优化,能够在各种条件下高效生成二维码。无论是生成单个二维码还是批量生成,都能快速且稳定地完成。 最后,Android二维码生成库还提供了简单易用的接口和示例代码,使得开发者可以快速上手并集成到自己的项目中。无论是初学者还是有经验的开发者,都可以轻松使用该库来生成二维码。 综上所述,Android二维码生成库是一种功能强大、兼容性好、高性能和稳定的开发工具,可以帮助开发者在Android平台上轻松生成个性化的二维码。无论是商业应用还是个人项目,都可以从中受益。 ### 回答2: Android二维码生成库是一种用于生成二维码的开源库。在Android开发中,我们可以通过使用这个库来轻松地生成二维码,并可以根据需求设置二维码的样式、大小和内容等属性。 Android二维码生成库通常提供了一个专门的API或者类,开发者可以通过调用这些方法,传入需要的参数来生成二维码。通常,我们需要传入的参数包括二维码的内容、二维码的宽度和高度等信息。生成二维码的过程通常是通过计算生成的图片的像素来实现的。生成的二维码可以保存为图片文件,也可以直接在应用中显示出来。 Android二维码生成库通常支持多种二维码格式,包括普通的二维码、带有Logo的二维码、带有颜色的二维码等。有些库还支持自定义二维码的样式,例如可以设置二维码的背景色、前景色或者在二维码中间添加Logo等。 使用Android二维码生成库可以方便快捷地生成二维码,无论是生成付款二维码、产品推广二维码还是其他类型的二维码,都可以轻松实现。同时,这些库通常有很好的兼容性,可以适用于不同版本的Android系统,并且提供了丰富的文档和示例来帮助开发者更好地使用。 总之,Android二维码生成库是开发Android应用时非常方便的工具,可以帮助开发者轻松实现二维码生成功能,提升应用的用户体验和功能扩展性。 ### 回答3: Android二维码生成库是一种在Android平台上使用的工具库,用于快速生成二维码。通过使用这种库,开发者可以方便地生成个性化的二维码图像,以满足不同需求。 Android二维码生成库通常提供了丰富的API和功能,可以设置二维码的大小、颜色、边距、错误纠正级别等属性,并支持在二维码中添加文本、网址、联系方式等额外信息。开发者可以根据自己的需求自定义这些属性,以生成符合预期的二维码。 使用Android二维码生成库,开发者只需引入相应的库文件,并在代码中调用相应的方法即可生成二维码。一般来说,生成二维码的步骤包括设置二维码的内容、生成二维码位图、将位图显示在界面上或保存为文件等操作。通过调整参数和样式,开发者可以生成不同风格和类型的二维码。 Android二维码生成库的优点是方便易用、功能丰富、效果灵活。开发者可以根据自己的需求选择适合的库来使用,以实现二维码生成功能。此外,由于二维码的应用非常广泛,使用这种库可以在Android应用中快速实现二维码相关的功能,提升用户的体验和便利性。 总之,Android二维码生成库是一种用于在Android平台上生成二维码的工具库,具有方便易用、功能丰富、效果灵活等优点。通过使用这种库,开发者可以快速生成二维码,以实现各种二维码相关的功能

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值