国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 實現銀聯刷卡機消費后手動簽名的功能(示例代碼)

2019-10-22 18:18:24
字體:
來源:轉載
供稿:網友

幾天前去物管交物業費,物管工作人員說小區引進高新產品,使用銀行卡消費后,不需要拿筆在銀聯機上簽名,直接用手指觸摸實現消費簽名,當時心想,果然是高科技,機子外形如下左圖,簽名如下右圖。

android,銀聯刷卡,手動簽名 android,銀聯刷卡,手動簽名

仔細一看,其實就是一個觸摸屏,用戶在上面直接手動簽名,實現這個功能其實并不復雜,我們自定義一個控件,繼承view,使用 Canvas的drawLine,drawPoint這兩個方法來實現這個功能。

首先自定義控件 MDrawLineView

package com.view;import android/146948.html">android.content.Context;import android.graphics.Bitmap;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.PorterDuff;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;import android.widget.LinearLayout;/** * Created by jiang on 2017/12/25. */public class MDrawLineView extends View { public MDrawLineView(Context context){  super(context); } public MDrawLineView(Context context,AttributeSet attrs){  super(context, attrs);  paint=new Paint(Paint.DITHER_FLAG);//創建一個畫筆  if(bitmap==null){   bitmap = Bitmap.createBitmap(900, 1200, Bitmap.Config.ARGB_8888); //設置位圖的寬高  }  canvas=new Canvas();  canvas.setBitmap(bitmap);  paint.setStyle(Paint.Style.STROKE);//設置非填充  paint.setStrokeWidth(5);//筆寬5像素  paint.setColor(Color.RED);//設置為紅筆  paint.setAntiAlias(true);//鋸齒不顯示 } @Override protected void onDraw(Canvas canvas) {  super.onDraw(canvas);  if(bitmap==null){   bitmap = Bitmap.createBitmap(900, 1200, Bitmap.Config.ARGB_8888); //設置位圖的寬高  }  canvas.drawBitmap(bitmap,0,0,null); } public void clear(){  canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); } @Override public boolean onTouchEvent(MotionEvent event) {  switch (event.getAction()){   case MotionEvent.ACTION_MOVE: //用戶手指在屏幕上移動畫線    canvas.drawLine(mov_x,mov_y,event.getX(),event.getY(),paint);    invalidate();    break;   case MotionEvent.ACTION_DOWN://用戶手指按下時畫起點    mov_x=(int) event.getX();    mov_y=(int) event.getY();    canvas.drawPoint(mov_x,mov_y,paint);    invalidate();    break;   case MotionEvent.ACTION_UP:    break;  }  mov_x=(int) event.getX();  mov_y=(int) event.getY();  return true;  //return super.onTouchEvent(event); } private int mov_x;//聲明起點x坐標 private int mov_y;//聲明起點y坐標 private Paint paint;//聲明畫筆 private Canvas canvas;//畫布 private Bitmap bitmap;//位圖 private int blcolor;}

布局xml代碼

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:padding="10dp" android:orientation="vertical"> <com.view.MDrawLineView  android:id="@+id/mDrawLine"  android:layout_width="300dp"  android:layout_height="400dp"  android:background="@drawable/bg_drawline" /> <Button  android:id="@+id/clearBut"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="清空" /></LinearLayout>

背景 bg_drawline .xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 描邊--> <stroke android:width="2dp" android:color="#45c01a"></stroke> <!-- 填充顏色 --> <solid android:color="#fff"></solid> <!-- 圓角 --> <corners android:radius="10dp"></corners></shape>

activity代碼

package com.cktest;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import com.view.MDrawLineView;/** * Created by jiang on 2017/12/25. */public class DrawLineAct extends AppCompatActivity implements View.OnClickListener{ @Override protected void onCreate(@Nullable Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.act_drawline);  mDrawLine = (MDrawLineView) findViewById(R.id.mDrawLine);  clearBut = (Button) findViewById(R.id.clearBut);  clearBut.setOnClickListener(this); } @Override public void onClick(View v) {  switch (v.getId()){   case R.id.clearBut:    mDrawLine.clear();    break;  } } private MDrawLineView mDrawLine; private Button clearBut;}

總結

以上所述是小編給大家介紹的Android 實現銀聯刷卡機消費后手動簽名的功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VEVB武林網網站的支持!


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 确山县| 田阳县| 天长市| 永平县| 望都县| 静安区| 苍梧县| 砚山县| 外汇| 呈贡县| 新营市| 东乌珠穆沁旗| 平山县| 淳安县| 会宁县| 奉节县| 娄底市| 巴彦县| 衡水市| 绥阳县| 翼城县| 开远市| 旬邑县| 海淀区| 龙胜| 临夏市| 贡觉县| 金乡县| 黄冈市| 金川县| 天峨县| 辽源市| 张掖市| 如皋市| 灵寿县| 泰州市| 新建县| 诸城市| 大新县| 政和县| 汾阳市|