Similar to the choice of the bank card interface, but also with a popupwindow, but the input password interface is a custom view, when the input six-bit password completed with the callback in the activity to obtain the entered password and toast display password. The effect chart is as follows:
Customize the view layout effect diagram and code as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/" Android "Android:layout_width=" Match_parent "android:layout_height=" wrap_content "android:background=" @drawable Bg_pop_window "android:orientation=" vertical > <linearlayout android:id= "@+id/ll_main_password" Android: Layout_width= "Match_parent" android:layout_height= "Wrap_content" android:layout_alignparentbottom= "true" Android:
Background= "#fff" android:orientation= "vertical" > <relativelayout android:layout_width= "match_parent"
android:layout_height= "50DP" > <imageview android:id= "@+id/iv_pay_back" android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" android:layout_centervertical= "true" android:layout_marginleft= "10DP" android:background= "@drawable/back_white"/> <textview android:id= "@+id/tv_pay_title" Wrap_content "android:layout_height=" Wrap_content "android:layout_centerhorizontal=" true "Android:layout_marginleft= "15DP" android:layout_margintop= "15DP" android:text= "title" android:textcolor= "#333" android:textsize= "18DP"/ > </RelativeLayout> <view android:layout_width= "match_parent" android:layout_height= "0.5DP" Android: background= "#e5e5e5"/> <!--6-bit cipher box layout requires a rounded border of shape to be a layout background--> <linearlayout android:layout_width= " Match_parent "android:layout_height=" wrap_content "android:layout_marginleft=" 20DP "android:layout_marginright=" 20DP "android:layout_margintop=" 20DP "android:background=" @drawable/shape_input_area "android:orientation="
Horizontal "> <!--inputtype set hidden password clear textsize set a little larger, otherwise" dot "is too small, not beautiful--> <textview android:id=" @+id/tv_pass1 " Android:layout_width= "0DP" android:layout_height= "Wrap_content" android:layout_weight= "1" android:gravity= "center "Android:inputtype=" Numberpassword "android:paddingbottom=" 5DP "android:paddingtop=" 5DP "android:textsize=" 32SP "/ > <view android:layout_width= "1DP" android:layout_height= "Match_parent" android:background= "#E5e5e5 "/> <textview android:id=" @+id/tv_pass2 "android:layout_width=" 0DP "android:layout_height=" Wrap_ Content "android:layout_weight=" 1 "android:gravity=" center "android:inputtype=" Numberpassword "Android:
Paddingbottom= "5DP" android:paddingtop= "5DP" android:textsize= "32sp"/> <view android:layout_width= "1DP"
android:layout_height= "Match_parent" android:background= "#e5e5e5"/> <textview android:id= "@+id/tv_pass3" Android:layout_width= "0DP" android:layout_height= "Wrap_content" android:layout_weight= "1" android:gravity= "center "Android:inputtype=" Numberpassword "android:paddingbottom=" 5DP "android:paddingtop=" 5DP "android:textsize=" 32SP "/
> <view android:layout_width= "1DP" android:layout_height= "match_parent" android:background= "#e5e5e5"/> <textview android:id= "@+id/tv_pass4" android:layout_width= "0DP" android:layout_height= "Wrap_content" Android: layout_weight= "1" android:gravity= "center" android:inputtype= "Numberpassword" android:paddingbottom= "5DP" Android: Paddingtop= "5DP" android:textsize= "32sp"/> <view android:layout_width= "1DP" android:layout_height= "Match_parent" "android:background=" #e5e5e5 "/> <textview android:id=" @+id/tv_pass5 "android:layout_width=" 0DP "Android: layout_height= "Wrap_content" android:layout_weight= "1" android:gravity= "center" android:inputtype= "NumberPassword" "Android:paddingbottom=" 5DP "android:paddingtop=" 5DP "android:textsize=" 32sp "/> <view android:layout_width=" 1DP "android:layout_height=" match_parent "android:background=" #e5e5e5 "/> <textview android:id=" @+id/tv_pass6 "Android:layout_width=" 0DP "android:layout_height=" Wrap_content "android:layout_weight=" 1 "android:gravity=" Center "android:inputtype=" Numberpassword "android:paddingbottom=" 5DP "android:paddingtop=" 5DP "android:textsize=" 32sp "/> </LinearLayout> <textview android:id=" @+id/tv_pay_forgetpwd "android:layout_width=" Wrap_ Content "android:layout_height=" wrap_content "android:layout_gravity=" right "android:layout_margin=" 15DP "android:text=" forgot password? "Android:textcolor=" #354EEF/> <!--input keyboard--> <gridview android:id= "@+id/gv_keybord" android:layout_width = "Match_parent" android:layout_height= "wrap_content" android:layout_below= "@id/ll_main_password" Android:layout_ margintop= "30DP" android:horizontalspacing= "0.5DP" android:background= "#8E8E8E" android:numcolumns= "3" Android: verticalspacing= "0.5DP"/> </LinearLayout> </RelativeLayout>
Java code
/** * Created by Zhpan on 2016/9/25. * * public class Payview extends relativelayout{private mainactivity mcontext; private String Mstringpassword;//Enter the password PRI Vate textview[] MTEXTVIEWPSW; Save 6 TextView Private GridView Mgridview with array;
Pay keyboard layout private arraylist<map<string, string>> valuelist;
Private ImageView Mimageviewcancel;
Private TextView MTEXTVIEWFORGETPSW;
private int currentindex = -1;//used to record the current input cipher grid location private View Mview;
Private TextView Mtextviewtitle;
Private TextView Mtextviewdel; Public Payview {Super (context, NULL);} public Payview (context, AttributeSet attrs) {Super (cont
ext, attrs);
Mcontext = (mainactivity) context;
Mview = view.inflate (context, r.layout.pay_view, null);
ValueList = new arraylist<> ();
MTEXTVIEWPSW = new Textview[6];
Mimageviewcancel = (ImageView) Mview.findviewbyid (r.id.iv_pay_back);
Mtextviewpsw[0] = (TextView) Mview.findviewbyid (R.ID.TV_PASS1); MTEXTVIEWPSW[1] = (TextView) Mview.findviewbyid (r.id.tv_pass2);
MTEXTVIEWPSW[2] = (TextView) Mview.findviewbyid (R.ID.TV_PASS3);
MTEXTVIEWPSW[3] = (TextView) Mview.findviewbyid (R.ID.TV_PASS4);
MTEXTVIEWPSW[4] = (TextView) Mview.findviewbyid (R.ID.TV_PASS5);
MTEXTVIEWPSW[5] = (TextView) Mview.findviewbyid (R.ID.TV_PASS6);
Mgridview = (GridView) Mview.findviewbyid (R.id.gv_keybord);
Mtextviewtitle = (TextView) Mview.findviewbyid (r.id.tv_pay_title);
MTEXTVIEWFORGETPSW = (TextView) Mview.findviewbyid (R.ID.TV_PAY_FORGETPWD);
Setview (); AddView (Mview); You must, otherwise do not display the number private void Setview () {for (int i = 1; i < i++) {map<string, string> Map
= new Hashmap<> (); if (I < ten) {map.put ("name", string.valueof (i));} else if (i = ten) {map.put ("name", "");} else if (i = =) {map.put ("name", string.valueof (0));} else if (i = =) {map.put ("name", "<-");} valuelist.add (MA
p);
} mgridview.setadapter (adapter); /** * Sets the listener method to trigger the/public void Setonfinishinput after the 6th digit is entered (final Onpasswordinputfinish pass) {mtextviewpsw[5].addtextchangedlistener (New Textwatcher () {@Override public void beforetextchanged (charsequence s, int start, int coun T, int after) {} @Override public void ontextchanged (charsequence s, int start, int before, int count) {} @Override Publ IC void aftertextchanged (Editable s) {if s.tostring (). Length () = 1) {Mstringpassword = ""; Each trigger will be mstringpassword empty and then retrieved, to avoid confusion due to input deletion and then input caused chaos for (int i = 0; i < 6; i++) {Mstringpassword = Mtextviewpsw[i].gettex
T (). toString (). Trim ();
Pass.inputfinish ();//interface to implement the method to complete the password input after the completion of the response Logic}}}); /** * Get input password/public String GetPassword () {return mstringpassword;}/** * Back to cancel payment ImageView/public ImageView getc
Ancel () {return mimageviewcancel;}/** * Returns the TextView/public TextView GETFORGETPSW () of the forgotten password mtextviewforgetpsw. /** * Returns the title of TextView/Public TextView GetTitle () {return mtextviewtitle;}//GridView adapter Baseadapter adapter = new B Aseadapter () {@Override public int getcount () {return valuelist.size ():} @Override public Object GetItem (int position) {return valuelist.get (position);} @Override public long getitemid (int position) {return posi
tion; @Override Public View getview (final int position, View Convertview, ViewGroup parent) {Viewholder holder; if (CONVERTVI EW = = NULL) {Convertview = View.inflate (mcontext, r.layout.item_pay_gride, null); holder = new Viewholder (); Holder.btnke
y = (TextView) Convertview.findviewbyid (R.id.btn_keys);
Convertview.settag (holder);
else {holder = (Viewholder) Convertview.gettag ();} holder.btnKey.setText (Valuelist.get (position). Get ("name"); if (position = = 9) {Holder.btnKey.setBackgroundResource (R.drawable.selector_key_del);} if (position = =) {Mtextviewde
L = Holder.btnkey;
Holder.btnKey.setBackgroundResource (R.drawable.selector_key_del); Holder.btnKey.setOnClickListener (New Onclicklistener () {@Override public void OnClick (View v) {if position < one &A mp;& currentindex!= 9&&position!=9) {//Click 0-9 button if (currentindex >=-1 && cuRrentindex < 5) {//Judge input position Mtextviewpsw[++currentindex].settext (Valuelist.get (position). Get ("name"));} else {if (position = 11) {//DOT Repel bar if (currentIndex-1 >=-1) {//To determine whether the deletion is complete mtextviewpsw[currentindex--].settext ("")
;
} if (position==9) {}}});
return convertview;
}
}; Static class Viewholder {public TextView Btnkey}}
Use this control directly in Popupwindow
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:layout_width=" match_parent "
android:layout_height=" match_parent ">
< Com.example.zhpan.mypayui.PayView
android:id= "@+id/pv_pop_win"
android:layout_width= "Match_parent"
android:layout_height= "match_parent"/>
</LinearLayout>
Display Pupupwindow in Mainactivity
public class Mainactivity extends Appcompatactivity implements View.onclicklistener {private TextView mtextview; private
Popupwindow Mpopupwindow;
Private View Popview;
Private Payview Mpayview; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (
R.layout.activity_main);
Initview ();
Setlistener (); private void Initview () {Mtextview = (TextView) Findviewbyid (R.id.tv_main_pay);} private void Setlistener () {Mtextvie
W.setonclicklistener (this); }//Show pinball window public void Showpopupwindow () {//init window Popview = view.inflate (this, r.layout.pop_window, null); Mpopupwindow =
New Popupwindow (Popview, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
Mpayview = (Payview) Popview.findviewbyid (R.id.pv_pop_win);
Mpayview.gettitle (). SetText ("Select bank card to account");
Set animation Mpopupwindow.setanimationstyle (R.style.popwin_anim_style);
Mpopupwindow.showasdropdown (Findviewbyid (R.id.ll_main), 0, 0); Mpopupwindow.setoutsidetouchable (tRue); Mpayview.setonfinishinput (New Onpasswordinputfinish () {@Override public void Inputfinish () {Toast.maketext (
Mainactivity.this, Mpayview.getpassword (), Toast.length_short). Show ();
}
});
Mpayview.getcancel (). Setonclicklistener (this);
MPAYVIEW.GETFORGETPSW (). Setonclicklistener (this); @Override public void OnClick (View v) {switch (V.getid ()) {case R.id.tv_main_pay:showpopupwindow (), break, Case r.id.
Iv_pay_back:mPopupWindow.dismiss ();
Break
Case R.id.tv_pay_forgetpwd:toast.maketext (mainactivity.this, "Forgotten password", toast.length_short). Show ();
Break }
}
}
The above is a small set to introduce the Android custom view fake Alipay input six-bit password function, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!