AndroidUI control series: Dialog (Dialog box)

Source: Internet
Author: User
The dialog box is indispensable in Android. when using the dialog box, you must use the AlertDialog. Builder class. Of course, in addition to the default system dialog box, you can also customize the dialog box. if a button is set in the dialog box, you need to listen to the event OnClickListener. The dialog box is indispensable in Android. when using the dialog box, you must use the AlertDialog. Builder class. Of course, in addition to the default system dialog box, you can also customize the dialog box. if a button is set in the dialog box, you need to listen to the event OnClickListener.

The following is an instance of the AlertDialog. Builder class and custom dialog box. when you click OK, the instance is transferred to the logon dialog box. after you enter the user name and password, the instance is transferred to the logon progress dialog box.

The custom dialog box consists of two textviews and two edittexts, that is, the logon dialog box. the layout file of the custom dialog box is the dialog. xml file. See the following

In addition, to use AlertDialog to create a dialog box, you need to understand several methods.

SetTitle (); set the title for the dialog box

SetIcon (); set the icon for the dialog box

SetMessage (); set the prompt information in the dialog box

SetItems (); set a list to be displayed in the dialog box, which is generally used to display several commands

SetSingleChoiceItems (); the setting dialog box displays a single-choice List.

SetMultiChoiceItems (); the setting dialog box displays a series of check boxes.

SetPositiveButton (); add the "yes" button to the dialog box

SetNegativeButton (); add the "no" button to the dialog box
DialogTest. java

Package org. hualang. dialog; import android. app. activity; import android. app. alertDialog; import android. app. dialog; import android. app. progressDialog; import android. content. dialogInterface; import android. OS. bundle; import android. view. layoutInflater; import android. view. view; public class DialogTest extends Activity {/** Called when the activity is first created. */ProgressDialog mydialog; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); Dialog dialog = new AlertDialog. builder (DialogTest. this ). setTitle ("logon prompt") // set the title. setMessage ("login required here") // the content displayed in the setting dialog box. setPositiveButton ("OK", // Set the OK button new DialogInterface. onClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {// Click OK to switch to the logon dialog box, LayoutInflater factory = LayoutInflater. from (DialogTest. this); // Get the custom dialog box final View DialogView = factory. inflate (R. layout. dialog, null); // create dialog box AlertDialog dlg = new AlertDialog. builder (DialogTest. this ). setTitle ("logon box "). setView (DialogView) // set the style of the custom dialog box. setPositiveButton ("OK", new DialogInterface. onClickListener () {// Set the listener event @ Override public void onClick (DialogInterface diich, int which) {// after the input is complete, click "OK" to log on to mydialog = ProgressDialog. show (DialogTest. this, "please wait... "," logging on... ", true); new Thread () {public void run () {try {sleep (3000);} catch (Exception e) {e. printStackTrace ();} finally {// login is complete. cancel the mydialog dialog box mydialog. dismiss ();}}}. start ();}}). setNegativeButton ("cancel", // Set the cancel button new DialogInterface. onClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {// Click Cancel and exit program DialogTest. this. finish ();}}). create (); // create dialog box dlg. show (); // Display dialog box }}). setNeutralButton ("Exit", new DialogInterface. onClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {// Click to exit the program DialogTest. this. finish ();}}). create (); // create button // Display dialog box dialog. show ();}}

Dialog. xml

 
 
  
  
  
  
 

The running result is as follows:

“?android:attr/textAppearanceLarge”“?android:attr/textAppearanceMedium”“?android:attr/textAppearanceSmall”

Usage:

android:textAppearance=”?android:attr/textAppearanceLarge”android:textAppearance=”?android:attr/textAppearanceMedium”android:textAppearance=”?android:attr/textAppearanceSmall”

Or

style=”?android:attr/textAppearanceLarge”style=”?android:attr/textAppearanceMedium”style=”?android:attr/textAppearanceSmall”

⑤ Android: scrollHorizontally = "true": determines whether a strip is displayed when the text exceeds the TextView width.

⑥ Android: autoText = "false": If set, the spelling of the input value is automatically corrected. There is no effect here. it works when the input method is displayed and entered. If this parameter is set to false, the sub-kinetic energy is disabled.

7. android: capitalize = "none": Set the uppercase letters. There is no effect here. you need to pop up the input method to see it.

Used android: password = "true": to show text in small dots. ", used when the password is entered

The above is the content of the Android UI control series: Dialog (Dialog box). For more information, see PHP Chinese network (www.php1.cn )!

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.