您好,登錄后才能下訂單哦!
這篇文章主要介紹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è)資訊頻道!
免責聲明:本站發(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)容。