allprojects {
repositories {
maven {
url 'https://jitpack.io'
}
}
}
dependencies {
compile 'com.github.goodboy321:Scan-Zxing:1.0'
}
<EditText android:id="@+id/et" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="输入内容,生成二维码" android:text="http://www.baidu.com" /> <Button android:background="@color/colorAccent" android:id="@+id/btn2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="生成二维码" /> <Button android:layout_marginTop="10dp" android:background="@color/colorPrimaryDark" android:id="@+id/btn1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="扫码(识别相册中二维码)" /> <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" /> <ImageView android:id="@+id/image_callback" android:layout_marginTop="10dp" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" />
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn1:
Intent intent = new Intent(mContext, CaptureActivity.class);
startActivityForResult(intent, REQUEST);
break;
case R.id.btn2:
image.setVisibility(View.VISIBLE);
//隐藏扫码结果view
imageCallback.setVisibility(View.GONE);
String content = et.getText().toString().trim();
Bitmap bitmap = null;
try {
bitmap = BitmapUtils.create2DCode(content);//根据内容生成二维码
tvResult.setVisibility(View.GONE);
image.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST) {
image.setVisibility(View.GONE);
imageCallback.setVisibility(View.VISIBLE);
String result = data.getStringExtra(CaptureActivity.SCAN_QRCODE_RESULT);
Bitmap bitmap = data.getParcelableExtra(CaptureActivity.SCAN_QRCODE_BITMAP);
if(bitmap != null){
imageCallback.setImageBitmap(bitmap);//现实扫码图片
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有