GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 自定义支付密码输入框微信版增加每个字符选中效果 · YXHTom/AndroidCustomView@269455d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/src/main
    • AndroidManifest.xml
    • java/com/allen/androidcustomview/widget
      • PayPsdInputView.java
    • res
      • layout
        • activity_pay_psd_view.xml
      • values
        • attrs.xml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/src/main/AndroidManifest.xml‎

Copy file name to clipboardExpand all lines: app/src/main/AndroidManifest.xml
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
<activity android:name=".tagview.TagActivity" />
2525
<activity android:name=".activity.AnimationBtnActivity" />
2626
<activity android:name=".activity.ProgressBarActivity" />
27-
<activity android:name=".activity.PayPsdViewActivity" />
27+
<activity android:name=".activity.PayPsdViewActivity"
28+
android:windowSoftInputMode="adjustPan|stateVisible"/>
2829
<activity android:name=".activity.AnimationViewActivity"></activity>
2930
</application>
3031

Collapse file

‎app/src/main/java/com/allen/androidcustomview/widget/PayPsdInputView.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/allen/androidcustomview/widget/PayPsdInputView.java
+24-10Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import com.allen.androidcustomview.R;
1515

16-
1716
import static android.graphics.Paint.ANTI_ALIAS_FLAG;
1817

1918
/**
@@ -83,8 +82,9 @@ public class PayPsdInputView extends EditText {
8382
* 竖直分割线的颜色
8483
*/
8584
private int divideLineColor = Color.GRAY;
85+
private int focusedColor = Color.BLUE;
8686
private RectF rectF = new RectF();
87-
87+
private RectF focusedRecF = new RectF();
8888
private int psdType = 0;
8989
private final static int psdType_weChat = 0;
9090
private final static int psdType_bottomLine = 1;
@@ -111,6 +111,11 @@ public class PayPsdInputView extends EditText {
111111
*/
112112
private String mComparePassword = null;
113113

114+
/**
115+
* 当前输入的位置索引
116+
*/
117+
private int position = 0;
118+
114119
private onPasswordListener mListener;
115120

116121
public PayPsdInputView(Context context, AttributeSet attrs) {
@@ -137,6 +142,7 @@ private void getAtt(AttributeSet attrs) {
137142
divideLineColor = typedArray.getColor(R.styleable.PayPsdInputView_divideLineColor, divideLineColor);
138143
psdType = typedArray.getInt(R.styleable.PayPsdInputView_psdType, psdType);
139144
rectAngle = typedArray.getDimensionPixelOffset(R.styleable.PayPsdInputView_rectAngle, rectAngle);
145+
focusedColor = typedArray.getColor(R.styleable.PayPsdInputView_focusedColor, focusedColor);
140146

141147
typedArray.recycle();
142148
}
@@ -174,7 +180,6 @@ private Paint getPaint(int strokeWidth, Paint.Style style, int color) {
174180
return paint;
175181
}
176182

177-
178183
@Override
179184
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
180185
super.onSizeChanged(w, h, oldw, oldh);
@@ -195,11 +200,12 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
195200
@Override
196201
protected void onDraw(Canvas canvas) {
197202
//不删除的画会默认绘制输入的文字
198-
// super.onDraw(canvas);
203+
// super.onDraw(canvas);
199204

200205
switch (psdType) {
201206
case psdType_weChat:
202207
drawWeChatBorder(canvas);
208+
drawItemFocused(canvas, position);
203209
break;
204210
case psdType_bottomLine:
205211
drawBottomBorder(canvas);
@@ -209,7 +215,6 @@ protected void onDraw(Canvas canvas) {
209215
drawPsdCircle(canvas);
210216
}
211217

212-
213218
/**
214219
* 画微信支付密码的样式
215220
*
@@ -229,6 +234,14 @@ private void drawWeChatBorder(Canvas canvas) {
229234

230235
}
231236

237+
private void drawItemFocused(Canvas canvas, int position) {
238+
if (position > maxCount - 1) {
239+
return;
240+
}
241+
focusedRecF.set(position * divideLineWStartX, 0, (position + 1) * divideLineWStartX,
242+
height);
243+
canvas.drawRoundRect(focusedRecF, rectAngle, rectAngle, getPaint(3, Paint.Style.STROKE, focusedColor));
244+
}
232245

233246
/**
234247
* 画底部显示的分割线
@@ -263,6 +276,7 @@ private void drawPsdCircle(Canvas canvas) {
263276
@Override
264277
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
265278
super.onTextChanged(text, start, lengthBefore, lengthAfter);
279+
this.position = start + lengthAfter;
266280
textLength = text.toString().length();
267281

268282
if (mComparePassword != null && textLength == maxCount) {
@@ -295,6 +309,11 @@ public String getPasswordString() {
295309
return getText().toString().trim();
296310
}
297311

312+
public void setComparePassword(String comparePassword, onPasswordListener listener) {
313+
mComparePassword = comparePassword;
314+
mListener = listener;
315+
}
316+
298317
/**
299318
* 密码比较监听
300319
*/
@@ -303,9 +322,4 @@ public interface onPasswordListener {
303322

304323
void onEqual(String psd);
305324
}
306-
307-
public void setComparePassword(String comparePassword, onPasswordListener listener) {
308-
mComparePassword = comparePassword;
309-
mListener = listener;
310-
}
311325
}
Collapse file

‎app/src/main/res/layout/activity_pay_psd_view.xml‎

Copy file name to clipboardExpand all lines: app/src/main/res/layout/activity_pay_psd_view.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
android:inputType="number"
1717
psd:maxCount="6"
1818
psd:psdType="weChat"
19-
psd:rectAngle="0dp" />
19+
psd:rectAngle="4dp" />
2020

2121
<com.allen.androidcustomview.widget.PayPsdInputView
2222
android:layout_width="match_parent"
Collapse file

‎app/src/main/res/values/attrs.xml‎

Copy file name to clipboardExpand all lines: app/src/main/res/values/attrs.xml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<attr name="divideLineWidth" format="dimension" />
1111
<attr name="divideLineColor" format="color" />
1212
<attr name="rectAngle" format="dimension" />
13+
<attr name="focusedColor" format="color"/>
1314
<attr name="psdType" format="enum">
1415
<enum name="weChat" value="0" />
1516
<enum name="bottomLine" value="1" />

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.