支付密码框

public class ShouquanMa_InputWidget extends LinearLayout {

	private static final int LENGTH = 6;
	private TextView[] password = new TextView[LENGTH];
	private EditText dymPassEdit;
	
	public InputCompeleListener oneditlistener = null;

	public ShouquanMa_InputWidget(Context context) {
		this(context, null);
	}

	public ShouquanMa_InputWidget(Context context, AttributeSet attrs) {
		super(context, attrs);
		initViews(context, attrs);
	}

	public void initViews(Context context, AttributeSet attrs) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.shouquanma_inputpass_widget, this, true);
		
		dymPassEdit = (EditText) view.findViewById(R.id.editpass);
		UnableEditTextCopyUtil.setEditHide_Copy_Paste_attr(dymPassEdit);
		password[0] = (TextView) view.findViewById(R.id.one);
		password[1] = (TextView) view.findViewById(R.id.two);
		password[2] = (TextView) view.findViewById(R.id.three);
		password[3] = (TextView) view.findViewById(R.id.four);
		password[4] = (TextView) view.findViewById(R.id.five);
		password[5] = (TextView) view.findViewById(R.id.six);
		dymPassEdit.requestFocus();
		
		Timer timer = new Timer();
		timer.schedule(new TimerTask() {
			public void run() {
				InputMethodManager imm = (InputMethodManager) dymPassEdit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
			}
		}, 998);
		
		
		OnClickListener listner = new OnClickListener() {

			@Override
			public void onClick(View v) {
				
				InputMethodManager imm = (InputMethodManager) dymPassEdit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
				dymPassEdit.requestFocus();
				
			}
		};

		for (int i = 0; i < password.length; i++) {
			
			password[i].setOnClickListener(listner);
		}

		dymPassEdit.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {

			}

			@Override
			public void afterTextChanged(Editable s) {

				if (dymPassEdit.getText().length() == 6) {

					if (oneditlistener != null) {
						new Handler().postDelayed(new Runnable() {
							@Override
							public void run() {
								oneditlistener.compeleteCallBack(true);
							}
						},150);

					}

				} else {
						 oneditlistener.compeleteCallBack(false);
				}

				String text = dymPassEdit.getText().toString();

				for (int i = 0; i < 6; i++) {
					password[i].setText("");
				}

				for (int i = 0; i < text.length(); i++) {
					password[i].setText(".");
				}
				dymPassEdit.requestFocus();
			}
		});		
	}
	
	public String getPassword() {
		return dymPassEdit.getText().toString();
	}


	public void setOnEditListenr(InputCompeleListener onEditListener) {
		if (onEditListener != null) {
			this.oneditlistener = onEditListener;
		}
	}
	

	/**
	 * 回调:当已经输入六位数
	 */
	public interface InputCompeleListener {

		/**
		 * 
		 */
		void compeleteCallBack(boolean b);
	}
	
	 /**
	  * 隐藏虚拟键盘
	  * @param v
	  */
    public  void hideKeyboard()
    {
        InputMethodManager imm = ( InputMethodManager ) dymPassEdit.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );     
      if ( imm.isActive( ) ) {     
          imm.hideSoftInputFromWindow( dymPassEdit.getApplicationWindowToken( ) , 0 );   
      }    
    }
    
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <LinearLayout
        android:id="@+id/passlayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:orientation="vertical">

        <View
            style="@style/widget_horizontal_line_style"
            android:layout_height="1dip"
            />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:weightSum="6">

            <View
                style="@style/widget_vertical_line_style"
                android:layout_width="1dip"
                android:layout_height="fill_parent" />

            <TextView
                android:id="@+id/one"
                style="@style/widget_password_style"
                android:layout_gravity="center_vertical"/>

            <View style="@style/widget_vertical_line_style" />

            <TextView
                android:id="@+id/two"
                style="@style/widget_password_style" />

            <View style="@style/widget_vertical_line_style" />

            <TextView
                android:id="@+id/three"
                style="@style/widget_password_style" />

            <View style="@style/widget_vertical_line_style" />

            <TextView
                android:id="@+id/four"
                style="@style/widget_password_style" />

            <View style="@style/widget_vertical_line_style" />

            <TextView
                android:id="@+id/five"
                style="@style/widget_password_style" />

            <View style="@style/widget_vertical_line_style" />

            <TextView
                android:id="@+id/six"
                style="@style/widget_password_style" />

            <View
                style="@style/widget_vertical_line_style"
                android:layout_width="1dip"

                />

        </LinearLayout>

        <View
            style="@style/widget_horizontal_line_style"
            android:layout_height="1dip" />
    </LinearLayout>


    <EditText
        android:id="@+id/editpass"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@null"
        android:cursorVisible="false"
        android:inputType="numberPassword"
        android:maxLength="6"
        android:textColor="#ffffff" />

</FrameLayout>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值