android验证验证码界面ui实现倒计时实现,BAT大厂面试总结

这篇博客介绍了如何在Android中实现验证码界面的UI,包括创建验证码字符串、绘制干扰线以及设置倒计时功能。同时,文章还提到了在面试中可能会遇到的相关知识点,如验证码生成和倒计时器的实现细节。
摘要由CSDN通过智能技术生成

padding_left = 0;

Bitmap bp = Bitmap.createBitmap(width, height, Config.ARGB_8888);

Canvas c = new Canvas(bp);

code = createCode();

c.drawColor(Color.WHITE);

Paint paint = new Paint();

paint.setTextSize(font_size);

for (int i = 0; i < code.length(); i++) {

randomTextStyle(paint);

randomPadding();

c.drawText(code.charAt(i) + “”, padding_left, padding_top, paint);

}

for (int i = 0; i < line_number; i++) {

drawLine(c, paint);

}

c.save( Canvas.ALL_SAVE_FLAG );

c.restore();//

return bp;

}

public String getCode() {

return code;

}

private String createCode() {

StringBuilder buffer = new StringBuilder();

for (int i = 0; i < codeLength; i++) {

buffer.append(CHARS[random.nextInt(CHARS.length)]);

}

return buffer.toString();

}

private void drawLine(Canvas canvas, Paint paint) {

int color = randomColor();

int startX = random.nextInt(width);

int startY = random.nextInt(height);

int stopX = random.nextInt(width);

int stopY = random.nextInt(height);

paint.setStrokeWidth(1);

paint.setColor(color);

canvas.drawLine(startX, startY, stopX, stopY, paint);

}

private int randomColor() {

return randomColor(1);

}

private int randomColor(int rate) {

int red = random.nextInt(256) / rate;

int green = random.nextInt(256) / rate;

int blue = random.nextInt(256) / rate;

return Color.rgb(red, green, blue);

}

private void randomTextStyle(Paint paint) {

int color = randomColor();

paint.setColor(color);

paint.setFakeBoldText(random.nextBoolean());

float skewX = random.nextInt(11) / 10;

skewX = random.nextBoolean() ? skewX : -skewX;

paint.setTe

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值