android dialog Box Summary

Source: Internet
Author: User
<span id="Label3"></p><span style="font-size:24px; color:#FF0000"><span style="font-size:24px; color:#FF0000">first, What is a dialog box? </span></span><br>A secondary window that contains buttons and various options through which specific commands or tasks can be completed. The Find and Replace dialog box differs from the window in that it has no maximized buttons, no minimized buttons, and most cannot change the size of the Shape. (the Open File dialog box is a Resizable) dialog box: a way for Human-machine communication, where the user sets the dialog box and the computer executes the corresponding command. The dialog box has a radio box, a check box, and so On.<br>To me, the dialog is a small box for conversations with Users. The most common thing you'll see is a pop-up dialog box.<br><span style="font-size:24px; color:#FF0000"><span style="font-size:24px; color:#FF0000">What is the use of the dialog box? </span></span><br>The dialog box does not block the main thread, can interact with the user simple, and gives a fresh feeling, the Good dialog box not only will not affect the user experience, but will let the user like the feeling of being disturbed.<br><p><p><span style="font-size:24px; color:#FF0000">third, How to use?</span></p></p><p><p><br><span style="font-size:24px; color:#FF0000"></span></p></p><span style="color:#3333FF"><span style="color:#3333FF">1. System dialog box</span></span><br>Alertdialog<br>ProgressDialog<br>Datepickerdialog<br>Timepickerdialog<br><span style="background-color:rgb(51,102,255)"><span style="background-color:rgb(51,102,255)">2. Customize dialog box</span></span><br>a, using the Layoutinflate and builder of the Setview method to achieve<br>b, Inheriting dialog-like replication Setcontentview implementation<br>Instance:<br>Activity_main.xml<br><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "fill_parent"<br>android:gravity= "center"<br>android:orientation= "vertical" ><br><br><button<br>Android:id= "@+id/show1"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>android:layout_margin= "10dp"<br>Android:background= "@drawable/button_background"<br>android:text= "dialog1"/><br><br><button<br>Android:id= "@+id/show2"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>android:layout_margin= "10dp"<br>Android:background= "@drawable/button_background"<br>android:text= "dialog2"/><br><br><button<br>Android:id= "@+id/show3"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>android:layout_margin= "10dp"<br>Android:background= "@drawable/button_background"<br>android:text= "dialog3"/><br><br></LinearLayout><br><br>Activity_dialog.xml<br><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "fill_parent"<br>android:orientation= "vertical" ><br><br><textview<br>Android:id= "@+id/textview1"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>android:gravity= "center"<br>android:text= "title"<br>Android:textappearance= "? android:attr/textappearancelarge"/><br><br><textview<br>Android:id= "@+id/textview2"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>android:gravity= "center"<br>Android:text= "this is a custom layout for alertdialog"/><br><br><textview<br>Android:id= "@+id/textview3"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>android:gravity= "center"<br>android:text= "/><br><br><textview<br>Android:id= "@+id/textview4"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>android:gravity= "center"<br>android:text= "how to layout how to layout"<br>Android:textappearance= "? android:attr/textappearancemedium"/><br><br><button<br>Android:id= "@+id/button1"<br>Android:layout_width= "fill_parent"<br>android:layout_height= "wrap_content"<br>Android:background= "@drawable/button_background"<br>android:text= "ok"/><br><br></LinearLayout><br><br>Mainactivity.java<br>public class Mainactivity extends Activity {<br>Private Button show1, show2, show3;<br>Datepickerdialog m = null;<br><br>@Override<br>protected void OnCreate (Bundle Savedinstancestate) {<br>Super.oncreate (savedinstancestate);<br>Setcontentview (r.layout.activity_main);<br>Show1 = (Button) Findviewbyid (r.id.show1);<br>Show2 = (Button) Findviewbyid (r.id.show2);<br>SHOW3 = (Button) Findviewbyid (r.id.show3);<br>Show1.setonclicklistener (mclicklistener);<br>Show2.setonclicklistener (mclicklistener);<br>Show3.setonclicklistener (mclicklistener);<br>}<br><br>Private View.onclicklistener Mclicklistener = new Onclicklistener () {<br><br>@Override<br>public void OnClick (View Arg0) {<br>TODO auto-generated Method Stub<br>int id = Arg0.getid ();<br>Switch (id) {<br>Case R.id.show1:<br>ShowDialog1 ();<br>Break<br>Case R.id.show2:<br>SHOWDIALOG2 ();<br>Break<br>Case R.id.show3:<br>ShowDialog3 ();<br>Break<br>Default<br>Break<br>}<br>}<br>};<br><br><span style="color:#33FF33"><span style="color:#33FF33">  </span></span><span style="color:#33FFFF"><span style="color:#33FFFF"><span style="color:#33FF33"><span style="color:#993399">private void ShowDialog1 () {<br>New Alertdialog.builder (this). Settitle ("dialog 1")<br>. Setmessage ("this is the simplest alertdialog"). Setpositivebutton ("ok", Null)<br>. Setneutralbutton ("what", null). Setnegativebutton ("cancel", Null)<br>. Create (). Show ();<br>}</span></span><br></span></span><br><span style="color:#330033">private void ShowDialog2 () {<br>Layoutinflater Inflater = Layoutinflater.from (this);<br>View view = Inflater.inflate (r.layout.activity_dialog, null);<br>Final Alertdialog Dialog = new Alertdialog.builder (this). setview (view). Create ();<br>Button OK = (button) View.findviewbyid (r.id.button1);<br>Ok.setonclicklistener (new View.onclicklistener () {<br><br>@Override<br>public void OnClick (View Arg0) {<br>TODO auto-generated Method Stub<br>Dialog.dismiss ();<br>}<br>});<br>Dialog.show ();<br>}</span><br><br><span style="color:#CC33CC">private void ShowDialog3 () {<br>New Mydialog (this). Show ();<br>}<br><br>Private class Mydialog extends dialog{<br><br>Public Mydialog (context Context) {<br>Super (context);<br>TODO auto-generated Constructor stub<br>This.setcontentview (r.layout.activity_dialog);<br>This.settitle ("title");<br>Button B = (button) Findviewbyid (r.id.button1);<br>B.setonclicklistener (new View.onclicklistener () {<br><br>@Override<br>public void OnClick (View Arg0) {<br>TODO auto-generated Method Stub<br>Dismiss ();<br>}<br>});<br>}</span><br>}<br>}<br><br><span style="font-size:24px; color:#FF0000"><span style="font-size:24px; color:#FF0000">Iv. Summary of attention</span></span><br>Attention:<br>1. Do not flood the dialog box<br>2. When customizing the dialog box, be aware that dismiss () or remove ()<br>3, there is a way to define the dialog box, that is, the theme of the activity is set to Theme.dialog<br>Summarize:<br>In this<span style="color:#FF0000"><span style="color:#FF0000">See Yan</span></span>era, to become a good programmer, first of all, to become a good designer.<br><br><p><p>android dialog Box Summary</p></p></span>

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.