溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android如何實現(xiàn)仿支付寶密碼輸入效果

發(fā)布時間:2021-06-28 09:35:07 來源:億速云 閱讀:160 作者:小新 欄目:移動開發(fā)

這篇文章主要介紹Android如何實現(xiàn)仿支付寶密碼輸入效果,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

效果圖

Android如何實現(xiàn)仿支付寶密碼輸入效果

1、如何使用,可以設(shè)置自己的進入退出動畫,不設(shè)置則沒有動畫效果,自己覺得封裝之后還是非常用好的。

private MyInputPwdUtil myInputPwdUtil;
@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 myInputPwdUtil = new MyInputPwdUtil(this);
 myInputPwdUtil.getMyInputDialogBuilder().setAnimStyle(R.style.dialog_anim);

 //可以定制自己進入退出動畫,不設(shè)置沒有動畫
 myInputPwdUtil.setListener(new InputPwdView.InputPwdListener() {
 @Override
 public void hide() {
  myInputPwdUtil.hide();
 }

 @Override
 public void forgetPwd() {
  Toast.makeText(MainActivity.this, "忘記密碼", Toast.LENGTH_SHORT).show();
 }

 @Override
 public void finishPwd(String pwd) {
  Toast.makeText(MainActivity.this, pwd, Toast.LENGTH_SHORT).show();
 }
 });
}
public void show(View view){
 myInputPwdUtil.show();
}

2、輸入框?qū)崿F(xiàn)主要代碼,就是繪制矩形和中間的圓形而已。

 int height = getHeight();
 int width = getWidth();
 //畫邊框
 RectF rect = new RectF(0, 0, width, height);
 borderPaint.setColor(borderColor);
 canvas.drawRoundRect(rect, borderRadius, borderRadius, borderPaint);
 //畫內(nèi)容區(qū)域
 RectF rectContent = new RectF(rect.left + defaultContentMargin, rect.top + defaultContentMargin, rect.right - defaultContentMargin, rect.bottom - defaultContentMargin);
 borderPaint.setColor(getResources().getColor(R.color.myInputPwdBase_gray));
 canvas.drawRoundRect(rectContent, borderRadius, borderRadius, borderPaint);

 //畫分割線:分割線數(shù)量比密碼數(shù)少1
 borderPaint.setColor(borderColor);
 borderPaint.setStrokeWidth(defaultSplitLineWidth);
 for (int i = 1; i < passwordLength; i++) {
 float x = width * i / passwordLength;
 canvas.drawLine(x, 0, x, height, borderPaint);
 }

 //畫密碼內(nèi)容
 float px, py = height / 2;
 float halfWidth = width / passwordLength / 2;
 for (int i = 0; i < textLength; i++) {
 px = width * i / passwordLength + halfWidth;
 canvas.drawCircle(px, py, passwordWidth, passwordPaint);
 }

3、作為library的module,在定義使用到的屬性的時候最好特別能區(qū)分開,設(shè)置特定的開頭,這樣能避免引入自己的工程之后導致沖突。

以上是“Android如何實現(xiàn)仿支付寶密碼輸入效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI