Android自定义交易密码框


/**
 * 交易密码弹出框
 * Created by Administrator on 2016/4/18.
 */
public class TradePasswordPopup extends BasePopupWindow {

    private Button popupSure, popcancel;
    private MyGridPasswordView passwordEdit;
    private LinearLayout tip_text_layout;
    private TextView incorrect_password;
    private OnFocus onFocus;
    private OnClickListener mListener;

    public TradePasswordPopup(Activity context) {
        super(context, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        mGravity = Gravity.CENTER;
    }

    protected boolean getFocusable() {
        return true;
    }

    @Override
    protected void initView(Activity context) {
        popupSure = (Button) mPopupView.findViewById(R.id.room_password_ok);
        popcancel = (Button) mPopupView.findViewById(R.id.room_password_cancel);
        passwordEdit = (MyGridPasswordView) mPopupView.findViewById(R.id.password_edit);
        incorrect_password = (TextView) mPopupView.findViewById(R.id.tx_tradepassword_error);
        tip_text_layout = (LinearLayout) mPopupView.findViewById(R.id.passworld_edit);
      /*  incorrect_password.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        incorrect_password.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mListener != null) {
                    mListener.onClick(incorrect_password);
                }
                dismiss();
            }
        }); */
        popupSure.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                onFocus.focus(passwordEdit.getPassWord());
            }
        });
        popcancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
               dismiss();
            }
        });
        passwordEdit.clearPassword();
        passwordEdit.forceInputViewGetFocus();
        showInputMethod(passwordEdit.getInputView(), 100);
    }

    public void showPopupWindow() {
       super.showPopupWindow();

    }

    public void clearPassword(){
        passwordEdit.clearPassword();
    }

    public void setAskPasswordListener(OnClickListener listener) {
        mListener = listener;
    }

    public void setListener(OnFocus onFocus) {
        this.onFocus = onFocus;
    }

    public interface OnFocus {
        void focus(String txt);
    }

    @Override
    protected Animation getShowAnimation() {
        return null;
    }

    @Override
    protected View getClickToDismissView() {
        return null;
    }

    @Override
    public View getPopupView() {
        return getPopupViewById(R.layout.popup_trade_password_view);
    }

    @Override
    public View getAnimaView() {
        return mPopupView;
    }

    @Override
    public boolean getPopupTransparent() {
        return false;
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/passworld_edit"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    android:gravity="center"
    android:orientation="vertical">


    <LinearLayout

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/popup_dialog_bg"
        android:gravity="center"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:orientation="vertical"
        android:visibility="visible">

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

            <Button
                android:id="@+id/room_password_cancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:background="@drawable/white_gray_bottomleft_radius"
                android:paddingBottom="20dp"
                android:paddingTop="20dp"
                android:text="@string/cancel"
                android:textColor="@color/text_b2"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/room_password_prompt_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:gravity="center"
                android:padding="10dp"
                android:text="@string/trade_input_trade_password"
                android:textColor="#343434"
                android:textSize="16dp" />


            <Button
                android:id="@+id/room_password_ok"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:background="@drawable/white_gray_bottomright_radius"
                android:paddingBottom="20dp"
                android:paddingTop="20dp"
                android:text="@string/ok"
                android:textColor="@color/bg_title"
                android:textSize="16sp" />
        </RelativeLayout>

        <com.bitvf.bitcoinWallet.view.MyGridPasswordView
            android:id="@+id/password_edit"
            android:layout_width="fill_parent"
            android:layout_height="50dip"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="@dimen/verify_code_edit_margin_bottom"
            android:layout_marginLeft="@dimen/verify_code_margin"
            android:layout_marginRight="@dimen/verify_code_margin"
            android:layout_marginTop="30dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="center"
            app:gpvLineColor="@color/divive_line"
            app:gpvLineWidth="@dimen/verify_code_border_width"
            app:gpvPasswordLength="6"
            app:gpvPasswordTransformation="●"
            app:gpvPasswordType="textPassword"
            app:gpvTextSize="18sp" />

        <TextView
            android:id="@+id/tx_tradepassword_error"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:textSize="14sp"
            android:layout_marginTop="5dip"
            android:layout_marginBottom="40dip"
            android:textColor="@color/text_warn"
            tools:text="密码错误,请重新输入"
            />


    </LinearLayout>
</LinearLayout>

关注公众号回复“小程序”获取1000个小程序打包源码。回复“大数据”获取多本大数据电子书

发表评论

电子邮件地址不会被公开。 必填项已用*标注