<Button android:text="Strat Scan" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="scan"/> <TextView android:id="@+id/tv_showResult" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!"/>
private TextView mTextView;
mTextView= (TextView) this.findViewById(R.id.tv_showResult);
//扫描二维码
//https://cli.im/text?2dd0d2b267ea882d797f03abf5b97d88二维码生成网站
public void scan(View view) {
startActivityForResult(new Intent(this, CaptureActivity.class),0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode==RESULT_OK){
Bundle bundle = data.getExtras();
if (bundle != null) {
String result=bundle.getString("result");
mTextView.setText(result);
}
}
}
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="com.example.hfs.zxingdemo.MainActivity"> <Button android:text="Strat Scan" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="scan"/> <TextView android:id="@+id/tv_showResult" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!"/> <EditText android:id="@+id/et_text" android:hint="Imput" android:layout_width="match_parent" android:layout_height="wrap_content"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="make" android:text="Make QRCode"/> <CheckBox android:id="@+id/cb_logo" android:layout_width="wrap_content" android:text="Logo" android:layout_height="wrap_content"/> <ImageView android:id="@+id/img_shouw" android:layout_width="wrap_content" android:layout_gravity="center" android:background="@mipmap/ic_launcher" android:layout_height="wrap_content"/> </LinearLayout>
package com.example.hfs.zxingdemo;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.camera2.CaptureRequest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.xys.libzxing.zxing.activity.CaptureActivity;
import com.xys.libzxing.zxing.encoding.EncodingUtils;
public class MainActivity extends AppCompatActivity {
private TextView mTextView;
private EditText mEditText;
private ImageView mImageView;
private CheckBox mCheckBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
mTextView= (TextView) this.findViewById(R.id.tv_showResult);
mEditText= (EditText) this.findViewById(R.id.et_text);
mImageView= (ImageView) this.findViewById(R.id.img_shouw);
mCheckBox= (CheckBox) this.findViewById(R.id.cb_logo);
}
//扫描二维码
//https://cli.im/text?2dd0d2b267ea882d797f03abf5b97d88二维码生成网站
public void scan(View view) {
startActivityForResult(new Intent(this, CaptureActivity.class),0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode==RESULT_OK){
Bundle bundle = data.getExtras();
if (bundle != null) {
String result=bundle.getString("result");
mTextView.setText(result);
}
}
}
//生成二维码 可以设置Logo
public void make(View view) {
String input = mEditText.getText().toString();
if (input.equals("")){
Toast.makeText(this,"输入不能为空",Toast.LENGTH_SHORT).show();
}else{
Bitmap qrCode = EncodingUtils.createQRCode(input, 500, 500,
mCheckBox.isChecked()? BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher):null);//CheckBox选中就设置Logo
mImageView.setImageBitmap(qrCode);
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有