안 드 로 이 드 알 리 페 이 비밀번호 입력 효과 패키지

알 리 페 이 입력 효 과 를 모방 하여 실현 하 는 것 은 매우 간단 합 니 다.바로 사각형 상자 와 원형 을 그 리 는 것 입 니 다.다른 것 은 조합 view 를 통 해 모든 기능 을 실현 합 니 다.간단 하지만 포장 해서 나중에 사용 하기에 편리 하고 공유 하 는 것 도 도움 이 되 기 를 바 랍 니 다.

1.어떻게 사용 하면 자신의 입장 을 설정 하고 애니메이션 을 종료 할 수 있 습 니 다.설정 하지 않 으 면 애니메이션 효과 가 없고 자신 이 포장 한 후에 도 매우 유용 하 다 고 생각 합 니 다.

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);

 //            ,       
 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.입력 상자 의 주요 코드 는 사각형 과 중간의 원형 을 그 리 는 것 입 니 다.

 int height = getHeight();
 int width = getWidth();
 //   
 RectF rect = new RectF(0, 0, width, height);
 borderPaint.setColor(borderColor);
 canvas.drawRoundRect(rect, borderRadius, borderRadius, borderPaint);
 //     
 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);

 //    :          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);
 }

 //     
 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 로 서 사용 하 는 속성 을 정의 할 때 특히 구분 하고 특정한 시작 을 설정 하면 자신의 프로젝트 를 도입 한 후에 충돌 을 피 할 수 있 습 니 다.
bug 가 있 으 면 지적 해 주 셔 서 감사합니다.
소스 코드
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기