支付密码框

来源:互联网 发布:英制螺纹怎么编程 编辑:程序博客网 时间:2024/05/01 14:23
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() {@Overridepublic 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() {@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Overridepublic void afterTextChanged(Editable s) {if (dymPassEdit.getText().length() == 6) {if (oneditlistener != null) {new Handler().postDelayed(new Runnable() {@Overridepublic 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
原创粉丝点击