Android About dialog Pop-up window

Source: Internet
Author: User

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"/&gt ; <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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.