Android 自定义密码框,密码+确认密码

/**
 * Dialog 显示视图
 * 
 * @author LanYan
 * 
 */
@SuppressLint("InflateParams")
public class KeyPayPasswordView {


@ViewInject(R.id.dyq_pay_keyboard_del)
private ImageView del;
@ViewInject(R.id.dyq_pay_keyboard_zero)
private ImageView zero;
@ViewInject(R.id.dyq_paykeyboard_one)
private ImageView one;
@ViewInject(R.id.dyq_pay_keyboard_two)
private ImageView two;
@ViewInject(R.id.dyq_pay_keyboard_three)
private ImageView three;
@ViewInject(R.id.dyq_pay_keyboard_four)
private ImageView four;
@ViewInject(R.id.dyq_pay_keyboard_five)
private ImageView five;
@ViewInject(R.id.dyq_pay_keyboard_sex)
private ImageView sex;
@ViewInject(R.id.dyq_pay_keyboard_seven)
private ImageView seven;
@ViewInject(R.id.dyq_pay_keyboard_eight)
private ImageView eight;
@ViewInject(R.id.dyq_pay_keyboard_nine)
private ImageView nine;
@ViewInject(R.id.dyq_pay_cancel)
private TextView cancel;
@ViewInject(R.id.dyq_pay_sure)
private TextView sure;
@ViewInject(R.id.dyq_pay_box1)
private TextView box1;
@ViewInject(R.id.dyq_pay_box2)
private TextView box2;
@ViewInject(R.id.dyq_pay_box3)
private TextView box3;
@ViewInject(R.id.dyq_pay_box4)
private TextView box4;
@ViewInject(R.id.dyq_pay_box5)
private TextView box5;
@ViewInject(R.id.dyq_pay_box6)
private TextView box6;
@ViewInject(R.id.dyq_pay_title)
private TextView title;


@ViewInject(R.id.dyq_qr_box1)
TextView qrbox1;
@ViewInject(R.id.dyq_qr_box2)
TextView qrbox2;
@ViewInject(R.id.dyq_qr_box3)
TextView qrbox3;
@ViewInject(R.id.dyq_qr_box4)
TextView qrbox4;
@ViewInject(R.id.dyq_qr_box5)
TextView qrbox5;
@ViewInject(R.id.dyq_qr_box6)
TextView qrbox6;
private final String TAG = "dongyaqin";
private ArrayList<String> mList = new ArrayList<String>();
private ArrayList<String> mList1 = new ArrayList<String>();
private View mView;
private OnPayListener listener;
private Context mContext;


public KeyPayPasswordView(String oriCode, Context mContext, OnPayListener listener) {
mView = LayoutInflater.from(mContext).inflate(R.layout.keypaypwd, null);
ViewUtils.inject(this, mView);
getDecorView(oriCode, mContext, listener);
}


public static KeyPayPasswordView getInstance(String oriCode, Context mContext, OnPayListener listener) {
return new KeyPayPasswordView(oriCode, mContext, listener);


}


public void getDecorView(String oriCode, Context mContext, OnPayListener listener) {
this.listener = listener;
this.mContext = mContext;
// content.setText("消费金额:"+monney+"元");
// authCode.setImageBitmap( Code.getInstance().createBitmap(oriCode,
// oriMask) );
}


@OnTouch({ R.id.dyq_pay_keyboard_del, R.id.dyq_pay_keyboard_zero, R.id.dyq_paykeyboard_one,
R.id.dyq_pay_keyboard_two, R.id.dyq_pay_keyboard_three, R.id.dyq_pay_keyboard_four,
R.id.dyq_pay_keyboard_five, R.id.dyq_pay_keyboard_sex, R.id.dyq_pay_keyboard_seven,
R.id.dyq_pay_keyboard_eight, R.id.dyq_pay_keyboard_nine, R.id.dyq_pay_cancel, R.id.dyq_pay_sure })


private boolean onTouch(View v, MotionEvent event) {


if (v == one) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.one);
Log.i(TAG, "dyqpaykeyboard_one ty ");
} else if (v == zero) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.zero);
Log.i(TAG, "dyqpay_keyboard_zero ty ");
} else if (v == two) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.two);
Log.i(TAG, "dyqpay_keyboard_two ty ");
} else if (v == three) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.three);
Log.i(TAG, "dyqpay_keyboard_three ty ");
} else if (v == four) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.four);
Log.i(TAG, "dyq_pay_keyboard_four ty ");
} else if (v == five) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.five);
Log.i(TAG, "dyq_pay_keyboard_five ty");
} else if (v == sex) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.sex);
Log.i(TAG, "dyq_pay_keyboard_sex ty");
} else if (v == seven) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.seven);
Log.i(TAG, "dyq_pay_keyboard_seven ty");
} else if (v == eight) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.eight);
Log.i(TAG, "dyq_pay_keyboard_eight ty");
} else if (v == nine) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.nine);
Log.i(TAG, "dyq_pay_keyboard_nine ty");
} else if (v == cancel) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.cancel);
Log.i(TAG, "dyq_pay_cancel ty");
} else if (v == sure) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.sure);
Log.i(TAG, "dyq_pay_sure ty");
} else if (v == del) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
parseActionType(KeyBoardEnum.del);
Log.i(TAG, "dyq_pay_keyboard_del ty");
}


return false;


}


@OnLongClick({R.id.dyq_pay_keyboard_del,R.id.dyq_pay_keyboard_zero, R.id.dyq_paykeyboard_one, R.id.dyq_pay_keyboard_two,
R.id.dyq_pay_keyboard_three, R.id.dyq_pay_keyboard_four, R.id.dyq_pay_keyboard_five,
R.id.dyq_pay_keyboard_sex, R.id.dyq_pay_keyboard_seven, R.id.dyq_pay_keyboard_eight,
R.id.dyq_pay_keyboard_nine, R.id.dyq_pay_cancel, R.id.dyq_pay_sure })
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
parseActionType(KeyBoardEnum.longdel);
return false;
}


private void parseActionType(KeyBoardEnum type) {
// TODO Auto-generated method stub
if (type.getType() == ActionEnum.add) {
if (mList.size() < 6) {
mList.add(type.getValue());
updateUi();
} else if (mList1.size() < 6) {
mList1.add(type.getValue());
updateUi();
}
} else if (type.getType() == ActionEnum.delete) {
if (mList1.size() > 0) {
mList1.remove(mList1.get(mList1.size() - 1));
updateUi();
} else if (mList.size() > 0) {
mList.remove(mList.get(mList.size() - 1));
updateUi();
}
} else if (type.getType() == ActionEnum.cancel) {
listener.onCancelPay();
} else if (type.getType() == ActionEnum.sure) {
if (mList.size() < 6 || mList1.size() < 6) {
Toast.makeText(mContext, "支付密码必须6位", Toast.LENGTH_SHORT).show();
} else if (mList.size() == 6 && mList1.size() == 6) {
String payValue = "";
for (int i = 0; i < mList.size(); i++) {
payValue += mList.get(i);
}
Log.i("dongyaqin", payValue + "输入密码");
String payString = "";
for (int j = 0; j < mList1.size(); j++) {
payString += mList1.get(j);
}
Log.i("dongyaqin", payString + "输入密码");
if (payValue.equals(payString)) {
listener.onSurePay(payValue);
listener.onSuccess(mContext);
Log.i("dongyaqin", "支付成功");
// Toast.makeText(mContext, "支付成功",
// Toast.LENGTH_SHORT).show();


} else {
Log.i("dongyaqin", "密码不一致");
Toast.makeText(mContext, "密码不一致", Toast.LENGTH_SHORT).show();
}
}
} else if (type.getType() == ActionEnum.longClick) {
mList.clear();
updateUi();
}


}


private void updateUi() {
// TODO Auto-generated method stub
if (mList.size() == 0) {
box1.setText("");
box2.setText("");
box3.setText("");
box4.setText("");
box5.setText("");
box6.setText("");


} else if (mList.size() == 1) {
box1.setText(mList.get(0));
box2.setText("");
box3.setText("");
box4.setText("");
box5.setText("");
box6.setText("");


} else if (mList.size() == 2) {
box1.setText(mList.get(0));
box2.setText(mList.get(1));
box3.setText("");
box4.setText("");
box5.setText("");
box6.setText("");


} else if (mList.size() == 3) {
box1.setText(mList.get(0));
box2.setText(mList.get(1));
box3.setText(mList.get(2));
box4.setText("");
box5.setText("");
box6.setText("");


} else if (mList.size() == 4) {
box1.setText(mList.get(0));
box2.setText(mList.get(1));
box3.setText(mList.get(2));
box4.setText(mList.get(3));
box5.setText("");
box6.setText("");


} else if (mList.size() == 5) {
box1.setText(mList.get(0));
box2.setText(mList.get(1));
box3.setText(mList.get(2));
box4.setText(mList.get(3));
box5.setText(mList.get(4));
box6.setText("");


} else if (mList.size() == 6) {
box1.setText(mList.get(0));
box2.setText(mList.get(1));
box3.setText(mList.get(2));
box4.setText(mList.get(3));
box5.setText(mList.get(4));
box6.setText(mList.get(5));


}


if (mList1.size() == 0) {


qrbox1.setText("");
qrbox2.setText("");
qrbox3.setText("");
qrbox4.setText("");
qrbox5.setText("");
qrbox6.setText("");
} else if (mList1.size() == 1) {


qrbox1.setText(mList1.get(0));
qrbox2.setText("");
qrbox3.setText("");
qrbox4.setText("");
qrbox5.setText("");
qrbox6.setText("");


} else if (mList1.size() == 2) {


qrbox1.setText(mList1.get(0));
qrbox2.setText(mList1.get(1));
qrbox3.setText("");
qrbox4.setText("");
qrbox5.setText("");
qrbox6.setText("");
} else if (mList1.size() == 3) {


qrbox1.setText(mList1.get(0));
qrbox2.setText(mList1.get(1));
qrbox3.setText(mList1.get(2));
qrbox4.setText("");
qrbox5.setText("");
qrbox6.setText("");


} else if (mList1.size() == 4) {


qrbox1.setText(mList1.get(0));
qrbox2.setText(mList1.get(1));
qrbox3.setText(mList1.get(2));
qrbox4.setText(mList1.get(3));
qrbox5.setText("");
qrbox6.setText("");


} else if (mList1.size() == 5) {
qrbox1.setText(mList1.get(0));
qrbox2.setText(mList1.get(1));
qrbox3.setText(mList1.get(2));
qrbox4.setText(mList1.get(3));
qrbox5.setText(mList1.get(4));
qrbox6.setText("");


} else if (mList1.size() == 6) {
qrbox1.setText(mList1.get(0));
qrbox2.setText(mList1.get(1));
qrbox3.setText(mList1.get(2));
qrbox4.setText(mList1.get(3));
qrbox5.setText(mList1.get(4));
qrbox6.setText(mList1.get(5));


}
}


public interface OnPayListener {
void onCancelPay();


void onSuccess(Context context);


void onSurePay(String password);
}


public View getView() {
return mView;
}

}



------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class DialogWidget extends Dialog {
Activity activity;
private View view;
private boolean isOutSideTouch = true;


public View getView() {
return view;
}


public void setView(View view) {
this.view = view;
}


public boolean isOutSideTouch() {
return isOutSideTouch;
}


public void setOutSideTouch(boolean isOutSideTouch) {
this.isOutSideTouch = isOutSideTouch;
}


public DialogWidget(Context context, int theme) {
super(context, theme);
}


public DialogWidget(Context context) {
super(context, 0);
// TODO Auto-generated constructor stub
}
public DialogWidget( Activity activity, View view ) {
super(activity, R.style.MyDialog);
this.activity = activity;
this.view = view;
}

public DialogWidget( Activity activity,View view,int theme){
super(activity,theme);
this.activity = activity;
this.view = view;
}
public DialogWidget( Activity activity,View view,int theme,boolean isOutSide ){
super(activity,theme);
this.activity = activity;
this.view = view;
this.isOutSideTouch = isOutSide;
}


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(view);
setCanceledOnTouchOutside( isOutSideTouch );
DisplayMetrics dm = new DisplayMetrics();//手机屏幕大小
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();
layoutParams.width = screenWidth;
layoutParams.height = screenHeight-60;
this.getWindow().setAttributes( layoutParams );


}

}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Activity中进行引用

dialogWidget = new DialogWidget(KeyPayPwdActivity.this, getKeyPayView());
dialogWidget.show();
}
private View getKeyPayView() {
// TODO Auto-generated method stub
return KeyPayPasswordView.getInstance(null, KeyPayPwdActivity.this, new OnPayListener() {

@Override
public void onSurePay(String password) {
// TODO Auto-generated method stub
openOnepayServiceReq( password );
}

@Override
public void onSuccess(Context context) {
// TODO Auto-generated method stub

}

@Override
public void onCancelPay() {
// TODO Auto-generated method stub
dialogWidget.dismiss();
KeyPayPwdActivity.this.finish();
}
}).getView();
}


-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

keypaypwd.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00000000"
    tools:context="com.zryf.sotpicbcnew.KeyPayPwdActivity" >


    <LinearLayout
        android:id="@+id/dyq_pay_input"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/dyq_keyboard"
        android:layout_margin="8dp"
        android:background="@drawable/edittext_bg_nor"
        android:orientation="vertical" >


        <TextView
            android:id="@+id/dyq_pay_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="@string/pay_title"
            android:textColor="#404040"
            android:textSize="16sp" />


        <TextView
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="8dp"
            android:background="#e1dfdf" />




        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:text="@string/pay_pwd_txt" />


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_margin="4dp"
                android:background="@drawable/sex_box_bg"
                android:orientation="horizontal" >


                <TextView
                    android:id="@+id/dyq_pay_box1"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_pay_box2"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_pay_box3"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_pay_box4"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_pay_box5"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                   android:maxLength="1"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_pay_box6"
                    style="@style/InputTextView"
                     android:maxLength="1"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
            </LinearLayout>
        </TableLayout>


        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp" >


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:text="@string/action_settings" />


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_margin="4dp"
                android:background="@drawable/sex_box_bg"
                android:orientation="horizontal" >


                <TextView
                    android:id="@+id/dyq_qr_box1"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_qr_box2"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_qr_box3"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_qr_box4"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_qr_box5"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_qr_box6"
                    style="@style/InputTextView"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
            </LinearLayout>


            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_margin="8dp"
                android:background="#e1dfdf" />


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="5dp"
                android:orientation="horizontal" >


                <TextView
                    android:id="@+id/dyq_pay_cancel"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="@string/pay_cancel"
                    android:textColor="#404040"
                    android:textSize="16sp" />


                <View
                    android:layout_width="1dp"
                    android:layout_height="fill_parent"
                    android:background="@drawable/sex_boxline_bg" />


                <TextView
                    android:id="@+id/dyq_pay_sure"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="@string/dyq_pay_sure"
                    android:textColor="#404040"
                    android:textSize="16sp" />
            </LinearLayout>
        </TableLayout>
    </LinearLayout>


    <LinearLayout
        android:id="@+id/dyq_keyboard"
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="40dp"
        android:background="#CFCFCF"
        android:orientation="vertical" >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" >


            <ImageView
                android:id="@+id/dyq_paykeyboard_one"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="1dp"
                android:layout_weight="1"
                android:background="@drawable/keyboard_one_selector"
                android:contentDescription="@string/action_settings" />


            <ImageView
                android:id="@+id/dyq_pay_keyboard_two"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="1dp"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="@drawable/keyboard_two_selector"
                android:contentDescription="@string/action_settings" />


            <ImageView
                android:id="@+id/dyq_pay_keyboard_three"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="1dp"
                android:layout_weight="1"
                android:background="@drawable/keyboard_three_selector"
                android:contentDescription="@string/action_settings" />
        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" >


            <ImageView
                android:id="@+id/dyq_pay_keyboard_four"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="1dp"
                android:layout_weight="1"
                android:background="@drawable/keyboard_four_selector"
                android:contentDescription="@string/action_settings" />


            <ImageView
                android:id="@+id/dyq_pay_keyboard_five"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="1dp"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="@drawable/keyboard_five_selector"
                android:contentDescription="@string/action_settings" />


            <ImageView
                android:id="@+id/dyq_pay_keyboard_sex"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="1dp"
                android:layout_weight="1"
                android:background="@drawable/keyboard_sex_selector"
                android:contentDescription="@string/action_settings" />
        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" >


            <ImageView
                android:id="@+id/dyq_pay_keyboard_seven"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="1dp"
                android:layout_weight="1"
                android:background="@drawable/keyboard_seven_selector"
                android:contentDescription="@string/action_settings" />


            <ImageView
                android:id="@+id/dyq_pay_keyboard_eight"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="1dp"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="@drawable/keyboard_eight_selector"
                android:contentDescription="@string/action_settings" />


            <ImageView
                android:id="@+id/dyq_pay_keyboard_nine"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="1dp"
                android:layout_weight="1"
                android:background="@drawable/keyboard_nine_selector"
                android:contentDescription="@string/action_settings" />
        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" >


            <ImageView
                android:id="@+id/pay_keyboard_space"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@drawable/keyboard_space"
                android:contentDescription="@string/action_settings" />


            <ImageView
                android:id="@+id/dyq_pay_keyboard_zero"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@drawable/keyboard_zero_selector"
                android:contentDescription="@string/action_settings" />


            <ImageView
                android:id="@+id/dyq_pay_keyboard_del"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@drawable/keyboard_del_selector"
                android:contentDescription="@string/action_settings" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>


以上是根据仿支付宝支付的事例进行修改后的样子。之所以修改是因为在经过自己反复测试生,发现存在一个问题:就是当连续的打开密码框Dialog时,会出现有输入不上密码的情况,事件也不会触发。最后发现,原来的KeyPayPasswordView中自定义的数字键盘所触发的是单击事件,后来改为onTouch事件后发现不会有这种情况发生。可又出现了新的问题,就是点击数字时背景不会变化,呃。。真是烦呢!

后来,又经过网上查看,发现onTouch事件与onLongClick事件间的一点关联,根据onTouch返回的值确定何时触发onLongClick事件,所以又给数字键加入了onLongClick事件后,完美解决了上述问题。真是技术不牛,累死人的节奏呀。

目前这个事例效果良好,没有发现其他bug,如果有大神看出破绽请提点。。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值