Custom Alertdialog (fillet + exit animation + custom layout)

Source: Internet
Author: User

The picture omitted does not upload ...

First Look at Activity_main.xml

<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 " >    <button        android:id= "@+id/button"        android:layout_width= "wrap_content"        android:layout_ height= "Wrap_content"        android:layout_centerinparent= "true"        android:text= "click Me, pop Up Alertdialog"/></ Relativelayout>
Mainactivity.java

Package Com.godinsec.alertdialog;import Com.godinsec.alertdialog.showdeledialog.onbtnclicklistener;import Android.app.activity;import Android.os.bundle;import Android.view.menu;import Android.view.MenuItem;import Android.view.view;import Android.widget.toast;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Findviewbyid (R.id.button). Setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View v) {New Showdeledialog (Mainactivity.this, New Onbtnclicklistener () {@Overridepublic void Onsure () {Toast.maketext ( Mainactivity.this, "Confirm operation", 0). Show (); @Overridepublic void OnExit () {Toast.maketext (Mainactivity.this, "Cancel operation", 0). Show ();}, OK, Cancel, prompt, Alertdialog content "). Show ();}});}}

Next look at the custom Alertdialog

Dele_allcontacts_dialog.xml

<?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 "> <relativelayout an Droid:id= "@+id/re_tip_dialog" android:layout_width= "300DP" android:layout_height= "120DP" Android:layout_cente Rinparent= "true" android:background= "@drawable/rounded_search_text" > <textview android:id= "             @+id/apptitle "android:layout_width=" wrap_content "android:layout_height=" Wrap_content " android:layout_marginleft= "10DP" android:layout_margintop= "10DP" android:text= "title"/> <t Extview android:id= "@+id/tips" android:layout_width= "Wrap_content" android:layout_height=            "Wrap_content" android:layout_below= "@id/apptitle" android:layout_alignleft= "@id/apptitle"  android:text= "Alertdialog Content"          android:layout_margintop= "20DP"/> <textview android:id= "@+id/sure" Android:la Yout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignparentright= "true         "android:text=" confirms "android:layout_below=" @id/tips "android:layout_margintop=" 20DP "/> <textview android:id= "@+id/cancel" android:layout_width= "Wrap_content" Android : layout_height= "wrap_content" android:layout_alignbottom= "@id/sure" android:text= "Cancel" and roid:layout_marginright= "30DP" android:layout_toleftof= "@id/sure"/> </relativelayout></relative Layout>
Rounded_search_text.xml (Fillet)

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android"    android:shape= "Rectangle" >    <solid android:color= "#FF7F24"/>    <corners        android: bottomleftradius= "4DP"        android:bottomrightradius= "4DP"        android:topleftradius= "4DP"        android: toprightradius= "4DP"/></shape>
Showdeledialog.java

Package Com.godinsec.alertdialog;import Android.app.dialog;import Android.content.context;import Android.graphics.drawable.bitmapdrawable;import Android.os.bundle;import Android.view.view;import Android.view.window;import Android.view.windowmanager;import Android.view.animation.animation;import Android.view.animation.animation.animationlistener;import Android.view.animation.scaleanimation;import Android.widget.relativelayout;import Android.widget.textview;public class Showdeledialog extends Dialog Implementsandroid.view.View.OnClickListener {Private Onbtnclicklistener onbtnclicklistener;private context context; private string Sure;private string Cancle;private string apptitle;private string tips;private TextView tv_dele_sure; Private TextView tv_dele_cancle;private TextView tv_apptitle;private TextView tv_tips;private relativelayout re_tip_ Dialog;public Showdeledialog (Context context,onbtnclicklistener onbtnclicklistener, string sure, String cancle,String AppTitle, String tips) {super (COntext); This.onbtnclicklistener = Onbtnclicklistener;this.context = Context;this.apptitle = AppTitle;this.tips = tips; This.sure = Sure;this.cancle = cancle;} @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);// Remove the default header requestwindowfeature (Window.feature_no_title); Setcontentview (r.layout.dele_allcontacts_dialog); tv_ Dele_sure = (TextView) Findviewbyid (r.id.sure); tv_dele_cancle = (TextView) Findviewbyid (r.id.cancel); tv_apptitle = ( TextView) Findviewbyid (r.id.apptitle); tv_tips = (TextView) Findviewbyid (r.id.tips); re_tip_dialog = (relativelayout) Findviewbyid (R.id.re_tip_dialog); Tv_dele_cancle.setonclicklistener (this), Tv_dele_sure.setonclicklistener (this) ; window window = This.getwindow (); Windowmanager.layoutparams params = This.getwindow (). GetAttributes ();//Remove corner black background window.setbackgrounddrawable (new Bitmapdrawable ());//Set the surrounding dark coefficient params.dimamount = 0.5f;window.setattributes (params);//Assign values to each TextView tv_dele_ Sure.settext (sure); Tv_dele_cancle.settext (cancle); Tv_apptitle.settext (AppTitle); Tv_tips.settext (tips);} Public interface Onbtnclicklistener {public void onsure ();p ublic void OnExit (); @Overridepublic void OnClick (View v) {switch (V.getid ()) {case r.id.cancel:onbtnclicklistener.onexit (); Alertdialogexitanim (); break;case r.id.sure:onbtnclicklistener.onsure (); Alertdialogexitanim (); Break;default: Break;}} private void Alertdialogexitanim () {scaleanimation scaleanimation = new Scaleanimation (1.0f, 0.0f,1.0f, 0.0f, Animation.absolute,re_tip_dialog.getwidth ()/2, Animation.absolute,re_tip_dialog.getheight ()/2); Scaleanimation.setduration (+); re_tip_dialog.startanimation (scaleanimation); Scaleanimation.setanimationlistener (New Animationlistener () {@Overridepublic void Onanimationstart (Animation Animation) {} @Overridepublic void Onanimationrepeat (animation animation) {} @Overridepublic void Onanimationend ( Animation Animation) {ShowDeleDialog.this.dismiss ();}});}}





Custom Alertdialog (fillet + exit animation + custom layout)

Related Article

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.