public class mydialog extends dialog implements android.view.view.onclicklistener{private button cancel; context context; View localview;private relativelayout clearallpan;protected mydialog (Context context) {super (context); this.context = context; @Overrideprotected void oncreate ( bundle savedinstancestate) {super.oncreate (savedinstancestate); requestwindowfeature (window.feature_no_title); // This Code change dialog default background, otherwise the edge of dialog hollow transparent and very wide // in short, not achieve the desired effect getwindow (). Setbackgrounddrawableresource (Android. R.color.transparent); layoutinflater inflater = ((AnimationActivity) context). Getlayoutinflater ();      LOCALVIEW = INFLAter.inflate (R.layout.animclearpan, null); Localview.setanimation (animationutils.loadanimation (context, r.anim.slide_bottom_to_top)); setcontentview (Localview); // This sentence plays a full-screen role getwindow (). SetLayout (layoutparams.fill_parent,layoutparams.fill_parent); Initview (); Initlistener ();} @Overridepublic boolean ontouchevent (motionevent event) {this.dismiss (); return Super.ontouchevent (event);} Private void initlistener () {cancel.setonclicklistener (this); Clearallpan.setonclicklistener (this); }private void initview () {cancel = (Button ) findviewbyid (R.id.cancel);clearallpan = (relativelayout) findviewbyid (R.id.clearallpan); }public void onclick (view v) {switch (V.getid ())  {CASE R.ID.CAncel: this.dismiss (); break;case r.id.clearallpan: Toast.maketext (context, "Please click outside this area", 0). Show (); break;}}}
The Animclearpan.xml layout file is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http// Schemas.android.com/apk/res/android " android:layout_width=" Fill_parent " android:layout_height= "Fill_parent" android:o rientation= "vertical" > <!-- android:background= "@drawable/ Clearpanbackground " --> <RelativeLayout android:id= "@+id/clearallpan" android:layout_width= "Fill_parent" android:layout_height= "300DP" android:layout_ Alignparentbottom= "true" android:background= "@android: Color/white" > <Button android:id= "@+id/cleaRall " android:layout_width=" Fill_parent " android:layout_height= "Wrap_content" android:layout_marginleft= "10dip" android:layout_marginright= "10dip" android:layout_ margintop= "20dip" android:layout_marginbottom= "10dip" android:text= "Delete all" android:textcolor= "#FFFFFFFF"/> <button android:id= "@+id/ Cancel " android:layout_width=" Fill_parent " android:layout_height= "Wrap_content" android:layout_ marginleft= "10dip" android:layout_marginright= "10dip" android:layout_margintop= "10dip" android:layout_marginbottom= "20dip" android:text= "Cancel" android:layout_below= "@id/clearall" android:textcolor= "#FFFFFFFF"/> </relativelayout> </RelativeLayout>
The animation effect Slide_bottom_to_top.xml file is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" Android:interpolator= "@android: Anim/accelerate_interpolator" > <translate android:duration= "an" Droid:fromydelta= "100.0%" android:toydelta= "10.000002%"/> <alpha android:duration= "Android" Oid:fromalpha= "0.0" android:toalpha= "1.0"/></set>
Custom dialog, then set to transparent background, then animate on view
2: We can also turn the acitivity into a dialog style, but there is a drawback: it is different mobile phone in the activity of the jump style has changed, when I set activity exit animation, no effect. So if the requirement requires a full-screen similar dialog style, customize the dialog display, do not turn the activity into dialog style.
Turn the activity into a dialog style.
1) activity as follows:
Package com.example.picpopupwindow;import android.app.activity;import android.os.bundle;import android.view.MotionEvent;import android.view.View;import android.view.View.OnClickListener; import android.widget.button;import android.widget.linearlayout;import android.widget.toast; public class selectpicpopupwindow extends activity implements onclicklistener{ private button btn_take_photo, btn_pick_photo, btn_cancel;private linearlayout layout; @Overrideprotected void oncreate (bundle savedinstancestate) {super.oncreate ( savedinstancestate) Setcontentview (r.layout.alert_dialog);btn_take_photo = (Button) This.findviewbyid (R.id.btn_take_photo);btn_pick_photo = (Button) this.findviewbyid (R.id.btn_ Pick_photo);btn_cancel = (Button) this.findviewbyid (r.id.btn_cancel); layout= (LinearLayout) Findviewbyid (r.id.pop_layout);//Add Selection window range listening can take precedenceGet the contact, i.e. no longer execute the ontouchevent () function, click Elsewhere when you execute the ontouchevent () function to destroy the Activitylayout.setonclicklistener (new Onclicklistener () {public void onclick (view v) {// todo auto-generated method stubtoast.maketext (Getapplicationcontext (), "Tip: Click outside the window to close the window! ", toast.length_short). Show ();}}); /Add button to monitor btn_cancel.setonclicklistener (this); Btn_pick_photo.setonclicklistener (this); Btn_take_ Photo.setonclicklistener (this);} Implement Ontouchevent touch screen function but destroy this activity@overridepublic boolean ontouchevent (motionevent event) When you tap the screen { Finish (); return true;} Public void onclick (view v) {switch (V.getid ()) {case r.id.btn_take_photo: Break;case r.id.btn_pick_photo:break;case r.id.btn_cancel:break;default:break;} Finish ();}}
Style alert_dialog.xml as follows
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns: Android= "Http://schemas.android.com/apk/res/android" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:gravity= "Center_ Horizontal " android:orientation=" vertical " ><LinearLayout android:id= "@+id/pop_layout" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:gravity= "Center_ Horizontal " android:orientation=" vertical " android:layout_ Alignparentbottom= "true" android:background= "@drawable/btn_style_alert_dialog_ Background " > <Button &nbSp; android:id= "@+id/btn_take_photo" android:layout_ marginleft= "20dip" android:layout_marginright= "20dip" android:layout_margintop= "20dip" android:layout_width= "Fill_parent" android:layout_ height= "wrap_content" android:text= "Photo" android:background= "@drawable/btn_style_alert_dialog_button" android:textstyle= "Bold" /> <button android:id= "@+id/btn_pick_ Photo " android:layout_marginleft=" 20dip android:layout_marginright= "20dip" android:layout_margintop= "5dip" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:text= "Select android:background= from the album" @ Drawable/btn_style_alert_dialog_button " android:textstyle = "Bold" /> <Button android:id= "@+id/btn_cancel" android:layout_marginleft= "20dip" android:layout_marginright= " 20dip " android:layout_margintop=" 15dip " Android:layout_marginbottom= "15dip" android:layout_width=" "Fill_parent" android:layout_height= "Wrap_content" android:text= "Cancel" android:background= "@drawable/btn_style_alert_dialog_cancel" android:textcolor= "#ffffff" Android:textstyle= "Bold" /></LinearLayout></RelativeLayout>
Configure the activity in the manifest file
<activity android:name= ". Selectpicpopupwindow "Android:theme=" @style/mydialogstylebottom "/> <activity
The Mydialogstylebottom style is as follows:
<style name= "Animbottom" parent= "@android: Style/animation" > <item name= "Android:windowenteranimation" > @anim/push_bottom_in</ item> <!-- <item name= "Android: Windowexitanimation "> @anim/push_bottom_out</item> --> </style> <style name= "Mydialogstylebottom" parent= "Android:Theme.Dialog" > <item name= "Android:windowanimationstyle" > @style/ Animbottom</item> <item name= "Android:windowFrame > @null </item> <!-- borders --> < Item name= "android:windowisfloating" >true</item> <!-- is on the activity --> &nBsp; <item name= "Android:windowistranslucent" >true</item> <!-- Translucent -- > <item name= "Android:windownotitle" >true</ item> <!-- Untitled --> <item name= " Android:windowbackground "> @android:color/transparent</item> <!-- Background Transparency --> <item name= "Android:backgrounddimenabled" >true</item > <!-- Blur --> </style>
The animated push_bottom_in.xml are as follows:
<?xml version= "1.0" encoding= "Utf-8"?><!--up and down slide-in--><set xmlns:android= "http://schemas.android.com/ Apk/res/android "> <translate android:duration=" "Android:fromydelta=" 100%p "Android:toyd Elta= "0"/> </set>
"Android" dialog from bottom to top (dialog full screen, modal display)