自定义的二维码 需要导入包
来源:互联网 发布:微信下单系统源码 编辑:程序博客网 时间:2024/06/11 20:07
//布局
<?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:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.qrcode.MainActivity"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="scan" android:text="扫描二维码" /> <TextView android:id="@+id/tv_ruselt" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="26sp" /> <EditText android:id="@+id/et_text" 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="生成二维码" /> <CheckBox android:id="@+id/is_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="check" /> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@mipmap/ic_launcher" /></LinearLayout>
//在Activity 里面写逻辑代码
package com.example.erweima;import android.content.Intent;import android.graphics.Bitmap;import android.graphics.BitmapFactory;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 com.xys.libzxing.zxing.activity.CaptureActivity;import com.xys.libzxing.zxing.encoding.EncodingUtils;public class MainActivity extends AppCompatActivity { private TextView mTv_Ruslet; private EditText mInput; private ImageView mImg; private CheckBox isLogo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTv_Ruslet = (TextView) findViewById(R.id.tv_ruselt); mInput = (EditText) findViewById(R.id.et_text); mImg = (ImageView) findViewById(R.id.img); isLogo = (CheckBox) findViewById(R.id.is_logo); } /** * 生成二维码 */ public void make(View view) { String input = mInput.getText().toString().trim(); //生成二维码,然后为二维码增加logo Bitmap bitmap = EncodingUtils.createQRCode(input, 500, 500, isLogo.isChecked() ? BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher) : null ); mImg.setImageBitmap(bitmap); } /** * 扫描二维码 */ public void scan(View view) { startActivityForResult(new Intent(MainActivity.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(); String result = bundle.getString("result"); mTv_Ruslet.setText(result); mInput.setText(result); } else if (resultCode == RESULT_CANCELED) { mTv_Ruslet.setText("扫描出错"); } }}
阅读全文
0 0
- 自定义的二维码 需要导入包
- toDF需要导入的包
- 使用ZBarSDK进行二维码扫描需要导入的类库
- struts1.3.8需要导入的包
- Eclipse 快速导入所有需要的包
- 配置Hibernate 3.6需要导入的包
- struts2+jQuery+jSon需要导入的包
- hibernate 需要导入的包--转
- Hibernate4需要导入的jar包
- 使用Hibernate需要导入的包
- Android问题:自动导入需要的包
- Struts初学之需要导入的包
- json使用时需要导入的包
- HibernateDaoSupport类需要导入的jar包
- HttpServlet需要导入的Jar包
- 导入导出需要的jar包
- 使用struts2需要导入的包
- Android Studio自定义组件时被继承的类红线提示需要导入V7包的widget组件
- 洛谷P1331 海战(老是打成寒战GG)
- 遍历求解连通块问题
- warning: MySQL-server-5.5.48-1.linux2.6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: N
- IOS Missing private key
- 20171103
- 自定义的二维码 需要导入包
- java环境变量
- java异常处理机制
- 读书笔记《C++ Primer》第五版——第八章 IO类
- 解决Internet共享访问被启用时出现一个错误null
- Spring Boot (一):简单的开始
- Android_绘制样式与操作进度条 跳转扫描二维码界面
- Java重载override
- MVP实现列表