Direct:
Implementation steps:
1. Main interface Activity_main.xml very easy, a button
<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= "@drawable/skin_background" > <button android:id= "@+id/show" android: Layout_width= "Match_parent" android:layout_height= "wrap_content" android:layout_alignparenttop= "true" android:gravity= "center" android:text= "Exit system" android:textsize= "20SP"/></relativelayout >
2. Pop-up layer style Actionsheet.xml
<?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=" wrap_content "android:background=" @color/transparent "android:orientation=" Vertica L "android:padding=" 5DP "> <textview android:id=" @+id/title "android:layout_width=" Match_parent " android:layout_height= "Wrap_content" android:background= "@drawable/actionsheet_top_normal" android:g ravity= "center" android:text= "@string/title" android:textcolor= "#8F8F8F" android:textsize= "16SP"/> ; <textview android:id= "@+id/content" android:layout_width= "match_parent" android:layout_height= "Wra P_content "android:background=" @drawable/actionsheet_bottom_selector "android:gravity=" center "Androi d:text= "@string/content" android:textcolor= "#FD4A2E" android:textsize= "16sp"/> <textview an Droid:id= "@+id/cancel"Android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:layout_margintop= "10DP" android:background= "@drawable/actionsheet_single_selector" android:gravity= "center" android:text= "@strin G/cancel "android:textcolor=" #037BFF "android:textsize=" 16SP "/></linearlayout>
3.ActionSheet class
public class Actionsheet {public interface onactionsheetselected {void OnClick (int whichbutton);} Private Actionsheet () {}public static Dialog Showsheet (context context, final onactionsheetselected actionsheetselected , Oncancellistener Cancellistener) {final Dialog dlg = new Dialog (context, r.style.actionsheet); Layoutinflater Inflater = (layoutinflater) context.getsystemservice (Context.layout_inflater_service); LinearLayout layout = (linearlayout) inflater.inflate (r.layout.actionsheet, NULL); final int cfullfillwidth = 10000; Layout.setminimumwidth (Cfullfillwidth); TextView mcontent = (TextView) Layout.findviewbyid (r.id.content); TextView Mcancel = (TextView) Layout.findviewbyid (r.id.cancel); Mcontent.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View v) {//TODO auto-generated method Stubactionsheetselected.onclick (0);d Lg.dismiss ();}); Mcancel.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated method StubactionsheetsElected.onclick (1);d Lg.dismiss ();}}); Window w = Dlg.getwindow (); Windowmanager.layoutparams LP = W.getattributes (); lp.x = 0;final int cmakebottom = 0;LP.Y = Cmakebottom;lp.gravity = Gravi Ty. CENTER;DLG.ONWINDOWATTRIBUTESCHANGED (LP);d Lg.setcanceledontouchoutside (false); if (cancellistener! = null) Dlg.setoncancellistener (Cancellistener);d Lg.setcontentview (layout);d lg.show (); return dlg;}}4.MainActivity
public class Mainactivity extends Activity implements Onactionsheetselected, Oncancellistener {@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Findviewbyid (r.id.show). Setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO Auto-generated method Stubactionsheet.showsheet (Mainactivity.this, Mainactivity.this, mainactivity.this);}); @Overridepublic void OnClick (int whichbutton) {//TODO auto-generated method Stubswitch (Whichbutton) {Case 0:showtoast (" Break;case 1:showtoast ("Cancel"); break;default:break;}} @Overridepublic void OnCancel (Dialoginterface dialog) {//TODO auto-generated method Stubshowtoast ("Cancel");} private void Showtoast (Charsequence charsequence) {Toast.maketext (this, charsequence, Toast.length_short). Show ();}}
Source
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Android About dialog Pop-up window