這篇文章主要介紹Android如何實(shí)現(xiàn)仿支付寶密碼輸入效果,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
效果圖
1、如何使用,可以設(shè)置自己的進(jìn)入退出動(dòng)畫,不設(shè)置則沒(méi)有動(dòng)畫效果,自己覺(jué)得封裝之后還是非常用好的。
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); //可以定制自己進(jìn)入退出動(dòng)畫,不設(shè)置沒(méi)有動(dòng)畫 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,在定義使用到的屬性的時(shí)候最好特別能區(qū)分開,設(shè)置特定的開頭,這樣能避免引入自己的工程之后導(dǎo)致沖突。
以上是“Android如何實(shí)現(xiàn)仿支付寶密碼輸入效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前標(biāo)題:Android如何實(shí)現(xiàn)仿支付寶密碼輸入效果-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://jinyejixie.com/article40/dseieo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、定制開發(fā)、小程序開發(fā)、靜態(tài)網(wǎng)站、關(guān)鍵詞優(yōu)化、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容