Implement custom dialog (similar to QQ click Exit after popup dialog box)

Source: Internet
Author: User

This is a long time ago to do, and then see the group there will always be someone to ask the question of custom dialog, stating that it is intended to po up, but also allow themselves to be developed in the future can be directly called, find resources too troublesome. The effect is really very simple to achieve.

In accordance with the Convention, first (lazy, directly on the PO on the implementation of the application):



Then the implementation is very simple:

Layout: Alert_dialog_layout.xml:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "match_parent "Android:layout_marginleft=" 10DP "android:layout_marginright=" 10DP "android:layout_height=" Wrap_content "Android oid:background= "@drawable/alertdialog_bg" > <linearlayout android:id= "@+id/btnset" Android:layout_w Idth= "Match_parent" android:layout_height= "45DP" android:layout_alignparentbottom= "true" Android:layo            ut_gravity= "Bottom" android:layout_margintop= "20DP" android:orientation= "vertical" > <view Android:layout_width= "Match_parent" android:layout_height= "1DP" android:background= "@drawable /alertdialog_bg_line "/> <linearlayout android:layout_width=" Match_parent "Android:layo ut_height= "wrap_content" android:orientation= "horizontal" > <button android:id=          "@+id/alert_btn_back"      Android:layout_width= "0DP" android:layout_height= "Match_parent" android:layout_weight= "1" android:background= "#00ffffff" android:text= "back to the app" Android:textcolor= "#4e                69f1 "android:textsize=" 15sp "/> <view android:layout_width=" 1px "            android:layout_height= "Match_parent" android:background= "@drawable/alertdialog_bg_line_h"/>                <button android:id= "@+id/alert_btn_exit" android:layout_width= "0DP" android:layout_height= "Match_parent" android:layout_weight= "1" android:background= "#00ffffff "Android:text=" exits the app "android:textcolor=" #4e69f1 "android:textsize=" 15SP "/&G        T </LinearLayout> </LinearLayout> <textview android:id= "@+id/str_logout" Android:layout_w Idth= "Match_paRent "android:layout_height=" wrap_content "android:layout_above=" @id/btnset "Android:layout_centerinp Arent= "true" android:layout_gravity= "Center_horizontal" android:layout_margintop= "10DP" Android:gravi Ty= "Center_horizontal" android:text= "really want to quit?" (⊙^⊙) "android:textsize=" 16sp "/> <textview android:layout_width=" Match_parent "Android:la        yout_height= "Wrap_content" android:layout_above= "@id/str_logout" android:layout_alignparenttop= "true" Android:layout_gravity= "Center_horizontal" android:layout_margintop= "10DP" android:gravity= "Center_horizont Al "Android:text=" Exit program "android:textsize=" 18SP "/></relativelayout>

Implementation of Java code:

private void Creatalertdialog () {mydialog = new Alertdialog.builder (mainactivity.this). Create (); Mydialog.show (); Mydialog.getwindow (). setlayout (750,450); Mydialog.getwindow (). setgravity (Gravity.center); MyDialog.getWindow (). Setcontentview (r.layout.alert_dialog_layout); Mydialog.getwindow (). Findviewbyid (R.id.alert_btn_back). Setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View v) {Mydialog.dismiss ();}}); Mydialog.getwindow (). Findviewbyid (R.id.alert_btn_exit). Setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {activitycollector.finishall ();}});}

This is the case, very simple, beautiful can also adjust the adjustment, this problem is not big.

Implement custom dialog (similar to QQ click Exit after popup dialog box)

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.