android 驗證碼,稍微修改
import java.util.Random;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
public class VerifyCodeView extends View {
Paint mPaint;
private final int TEXT_SIZE = 20;
public VerifyCodeView(Context context) {
super(context);
init();
}
public VerifyCodeView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public VerifyCodeView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
mPaint = new Paint();
/* Sawtooth */
mPaint.setAntiAlias(false);
/* Set the frame width of the paint */
mPaint.setStrokeWidth(4);
// set the font sieze
mPaint.setTextSize(TEXT_SIZE);
mPaint.setTextAlign(Paint.Align.CENTER);
}
protected void onDraw(Canvas canvas) {
/* set backgroud clolr */
canvas.drawColor(Color.GRAY);
canvas.save();
canvas.translate(10, 10);
/* set paint color */
mPaint.setColor(Color.BLUE);
// build random code
Random random = new Random();
String sRand = "";
for (int i = 0; i < 4; i++) {
String rand = String.valueOf(random.nextInt(10));
canvas.drawText(rand, TEXT_SIZE * i + 4, 10, mPaint);
sRand += rand;
}
saveCode(sRand);
canvas.restore();
}
/**
* Save coding in here
*
* @param code
*/
private void saveCode(String code) {
// TODO
ViewConstant.IDENTIFY_CODE_VALUE = code;
}
}
========================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Textview="http://schemas.android.com/apk/res/com.zcwfeng.identify"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="fill_parent">
<TextView android:id="@+id/txt_date" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Verify" />
<EditText android:id="@+id/identifyCode"
android:layout_width="100dp" android:layout_height="wrap_content"
android:layout_marginLeft="8dp" android:layout_marginRight="8dp" />
<com.zcwfeng.identify.VerifyCodeView
android:layout_width="90dp" android:layout_height="28dp"
android:layout_marginTop="10dp">
</com.zcwfeng.identify.VerifyCodeView>
<Button android:id="@+id/print" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="點我驗證"/>
</LinearLayout>
</LinearLayout>
===========================
package com.zcwfeng.identify;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.print);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText editText = (EditText) findViewById(R.id.identifyCode);
String code = editText.getText().toString();
if (code.equals(ViewConstant.IDENTIFY_CODE_VALUE)) {
System.err.println(code);
Toast.makeText(MainActivity.this, "ok--->" + code, Toast.LENGTH_LONG);
}else {
System.err.println("error------>"+code);
}
}
});
}
}
相關文章
- 滑動拼圖驗證碼水印Logo修改Go
- Android自定義View---驗證碼AndroidView
- 驗證碼原理及驗證
- laravel修改使用者模組的密碼驗證Laravel密碼
- 驗證碼---js重新整理驗證碼JS
- Android自定義方形驗證碼輸入框Android
- JavaScript驗證碼生成和驗證效果JavaScript
- 驗證碼機制之驗證碼重複使用
- 登入驗證碼生成kaptcha(輸入驗證碼)APT
- Laravel - 驗證碼Laravel
- PHP驗證碼PHP
- 驗證碼程式
- Android開發採坑篇之騰訊驗證碼Android
- easy-captcha實現驗證碼驗證APT
- 影片直播app原始碼,傳送驗證碼 驗證碼識別APP原始碼
- PHP 驗證身份證號碼PHP
- Android仿滴滴出行驗證碼輸入框效果Android
- Android View篇之自定義驗證碼輸入框AndroidView
- Android開發之自動填充簡訊驗證碼Android
- Android中實現簡訊驗證碼自動填入Android
- Android註冊功能--電話驗證和郵箱驗證Android
- 【驗證碼逆向專欄】某驗“初代”滑塊驗證碼逆向分析
- 精確驗證身份證號碼程式碼
- 隨機驗證碼隨機
- django 驗證碼框架Django框架
- laravel(五) 驗證碼Laravel
- Laravel - 驗證碼(captcha)LaravelAPT
- 驗證碼識別
- 身份證號碼驗證系統
- 身份證號碼之js驗證JS
- PHP算式驗證碼和漢字驗證碼的實現方法PHP
- Laravel 修改驗證異常的響應格式Laravel
- [翻譯] 如何修改 Laravel 的登入驗證Laravel
- Rails 4 驗證資訊漢化以及樣式修改AI
- 【驗證碼逆向專欄】某驗三代滑塊驗證碼逆向分析
- 【驗證碼逆向專欄】某驗四代滑塊驗證碼逆向分析
- Java 驗證碼、二維碼Java
- 生成驗證碼程式程式碼