Two pop-up box layouts:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" fill_parent " android:layout_height=" Wrap_content " android:layout_gravity= "center_horizontal|center_vertical" android:orientation= "vertical" > <LinearLayout android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:layout_marginleft= "20dip" android:layout_marginright= "20dip" android:background= "@drawable/alert" android:gravity= "center_horizontal" android:orientation= " Vertical "> <TextView android:id=" @+id/dialog_t Itle " android:layout_width=" Wrap_content "&nbsP android:layout_height= "wrap_content" Android: layout_margintop= "17dip" android:text= "about-to-call 323" &NB Sp android:textcolor= "#ffffff" android:textsize= "16dip" android:textstyle= "bold"/> <TextView &NB Sp android:id= "@+id/dialog_message" android:layout_width= " Wrap_content " android:layout_height=" wrap_content " & nbsp android:layout_margin= "10dip" android:gravity= "Center_horizontal" android:text= "is sure you want to proceed?" android:textcolor= "#ffFFFF " android:textsize=" 16dip "/> <linearlayout android:layout_width= "fill_parent" Android oid:layout_height= "Wrap_content" android:layout_marginbottom= "10dip" & nbsp android:layout_margintop= "10dip" android:gravity= " Center_horizontal " android:orientation=" Horizontal "> & nbsp <Button android:id= "@+id/cancel" &NBS P android:layout_width= "0dip" Android oid:layout_height= "40dip" android:layout_gravity= "left" & nbsp &NBSP; android:layout_marginleft= "10dip" Android:lay out_weight= "0.5" android:background= "@drawable/custom_button1" & nbsp android:text= "Cancel" &NB Sp Android:textcolor= "@color/white" android:textstyle= "bold"/>& nbsp <Button android:id= "@+id/ok" & nbsp android:layout_width= "0dip" &NBS P android:layout_height= "40dip" Android:layout_marginbottom = "10dip" android:layout_marginright= "10dip" &N Bsp &nbsP android:layout_weight= 0.5 Android:backgroun d= "@drawable/custom_button" android:text= "OK" android:textcolor= "@color/white" Android:textstyle= "Bold"/> </LinearLayout> </LinearLayout> </LinearLayout>
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" fill_parent " android:layout_height=" Wrap_content " android:layout_gravity= "center_horizontal|center_vertical" android:orientation= "vertical" > <LinearLayout android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:layout_marginleft= "20dip" android:layout_marginright= "20dip" android:background= "@drawable/alert" android:gravity= "center_horizontal" android:orientation= " Vertical "> <TextView android:id=" @+id/dialog_t Itle " android:layout_width=" Wrap_content "&nbsP android:layout_height= "wrap_content" Android: layout_margintop= "15dip" android:text= "about-to-call 323" &NB Sp android:textcolor= "#ffffff" android:textsize= "17dip" android:textstyle= "bold"/> <TextView &NB Sp android:id= "@+id/dialog_message" android:layout_width= " Wrap_content " android:layout_height=" wrap_content " & nbsp android:layout_margin= "10dip" android:gravity= "Center_horizontal" android:text= "is sure you want to proceed?" android:textcolor= "#ffFFFF " android:textsize=" 15dip "/> <linearlayout android:layout_width= "fill_parent" Android oid:layout_height= "Wrap_content" android:layout_marginbottom= "10dip" & nbsp android:layout_margintop= "10dip" android:gravity= " Center_horizontal " android:orientation=" Horizontal "> & nbsp <Button android:id= "@+id/ok" & nbsp android:layout_width= "fill_parent" Android oid:layout_height= "40dip" android:layout_marginbottom= "10dip" & nbsp &NBSp android:layout_marginleft= "10dip" Andro id:layout_marginright= "10dip" android:background= "@drawable/ Custom_button " android:text=" OK " android:textcolor= "@color/white" Android:text Size= "17dip" android:textstyle= "bold"/> &NB Sp </LinearLayout> </LinearLayout></LinearLayout>
Java files:
Package hi.braincol.example.iphonealert;/* No CONSTRAINTS! Just use the code under your thoughts! * Mail me at [email protected]** Licensed under the Apache License, Version 2.0 (the "License"); * Do not use thi s file except in compliance with the license.* obtain a copy of the License at** http://www.apache.org/license s/license-2.0** unless required by applicable law or agreed to in writing, software* distributed under the LICENSE is Dist Ributed on an ' as is ' basis,* without warranties or CONDITIONS of any KIND, either express OR implied.* see the License fo R the specific language governing permissions and* limitations under the license.*/import Android.app.activity;import and Roid.app.dialog;import Android.os.bundle;import Android.view.view;import Android.view.window;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.textview;public Class Mainscreenactivity extends activity {/** Called when the activity is first CreaTed. */button Buttonok,buttonokcancel; @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); Buttonok = (Button) Findviewbyid (R.id.button1); Buttonok.setonclicklistener (New Button.onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO Auto-generated Method Stubshowcustommessageok ("Confirmation", "Just click OK to continue!");}); Buttonokcancel = (Button) Findviewbyid (R.id.button2); Buttonokcancel.setonclicklistener (New Button.onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO Auto-generated method Stubshowcustommessage ("Alert", "is sure you want continue?");});} /** * It'll show the Ok/cancel dialog like iphone, make sure no keyboard are visible * * @param ptitle * titl E for Dialog * @param PMSG * msg for body */private void Showcustommessage (String pTitle, Final String pMsg) {final Dialog ldialog = new Dialog (mainscreenactivity.this,android. R.style.theme_translucent_notitlebar); ldialog.requestwindowfeature (Window.feature_no_title); Ldialog.setcontentview (R.layout.r_okcanceldialogview);((TextView) Ldialog.findviewbyid (R.id.dialog_title)). SetText (ptitle);((TextView) Ldialog.findviewbyid (R.id.dialog_message)). SetText (PMSG);((Button) Ldialog.findviewbyid (R.id.ok)). SetText ("OK");((Button) Ldialog.findviewbyid (R.id.cancel)). Setonclicklistener ( New Onclicklistener () {@Overridepublic void OnClick (View v) {//write your code to does things after users clicks Cancelldia Log.dismiss ();});( (Button) Ldialog.findviewbyid (R.id.ok)). Setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View V) {//write your code to does things after users clicks OK Ldialog.dismiss ();}); Ldialog.show ();} /** * It'll show the OK dialog like iphone, make sure no keyboard be visible * * @param ptitle * title for D Ialog * @param PMSG * msg for body */private void Showcustommessageok (String ptitle, final string pMsg) {final Dialog ldialog = new Dialog ( Mainscreenactivity.this,android. R.style.theme_translucent_notitlebar); ldialog.requestwindowfeature (Window.feature_no_title); Ldialog.setcontentview (R.layout.r_okdialogview);((TextView) Ldialog.findviewbyid (R.id.dialog_title)). SetText ( Ptitle);((TextView) Ldialog.findviewbyid (R.id.dialog_message)). SetText (PMSG);((Button) Ldialog.findviewbyid ( R.id.ok). SetText ("OK");((button) Ldialog.findviewbyid (R.id.ok)). Setonclicklistener (New Onclicklistener () {@ overridepublic void OnClick (View v) {//write your code to does things after users clicks Okldialog.dismiss ();}); Ldialog.show ();} }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
android-Imitation iOS popup box