加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090218034000/http://developer.android.com:80/reference/android/app/AlertDialog.html
public class

AlertDialog

extends Dialog
implements DialogInterface
java.lang.Object
   ↳ android.app.Dialog
     ↳ android.app.AlertDialog
Known Direct Subclasses

Class Overview

A subclass of Dialog that can display one, two or three buttons. If you only want to display a String in this dialog box, use the setMessage() method. If you want to display a more complex view, look up the FrameLayout called "body" and add your view to it:

 FrameLayout fl = (FrameLayout) findViewById(R.id.body);
 fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT));
 

Summary

Nested Classes
public class AlertDialog.Builder  
[Expand]
Inherited Constants
From interface android.content.DialogInterface
Protected Constructors
AlertDialog(Context context)
AlertDialog(Context context, int theme)
AlertDialog(Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener)
Public Methods
boolean onKeyDown(int keyCode, KeyEvent event)
A key was pressed down.
boolean onKeyUp(int keyCode, KeyEvent event)
A key was released.
void setButton(CharSequence text, Message msg)
void setButton(CharSequence text, DialogInterface.OnClickListener listener)
Set a listener to be invoked when button 1 of the dialog is pressed.
void setButton2(CharSequence text, Message msg)
void setButton2(CharSequence text, DialogInterface.OnClickListener listener)
Set a listener to be invoked when button 2 of the dialog is pressed.
void setButton3(CharSequence text, Message msg)
void setButton3(CharSequence text, DialogInterface.OnClickListener listener)
Set a listener to be invoked when button 3 of the dialog is pressed.
void setCustomTitle(View customTitleView)
void setIcon(Drawable icon)
void setIcon(int resId)
Set resId to 0 if you don't want an icon.
void setInverseBackgroundForced(boolean forceInverseBackground)
void setMessage(CharSequence message)
void setTitle(CharSequence title)
Set the title text for this dialog's window.
void setView(View view)
Set the view to display in that dialog.
Protected Methods
void onCreate(Bundle savedInstanceState)
Similar to onCreate(Bundle), you should initialized your dialog in this method, including calling setContentView(View).
[Expand]
Inherited Methods
From class android.app.Dialog
From class java.lang.Object
From interface android.content.DialogInterface
From interface android.view.KeyEvent.Callback
From interface android.view.View.OnCreateContextMenuListener
From interface android.view.Window.Callback

Protected Constructors

protected AlertDialog (Context context)

protected AlertDialog (Context context, int theme)

protected AlertDialog (Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener)

Public Methods

public boolean onKeyDown (int keyCode, KeyEvent event)

A key was pressed down.

If the focused view didn't want this event, this method is called.

The default implementation handles KEYCODE_BACK to close the dialog.

Parameters
keyCode The value in event.getKeyCode().
event Description of the key event.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public boolean onKeyUp (int keyCode, KeyEvent event)

A key was released.

Parameters
keyCode The value in event.getKeyCode().
event Description of the key event.
Returns
  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

public void setButton (CharSequence text, Message msg)

public void setButton (CharSequence text, DialogInterface.OnClickListener listener)

Set a listener to be invoked when button 1 of the dialog is pressed.

Parameters
text The text to display in button 1.
listener The DialogInterface.OnClickListener to use.

public void setButton2 (CharSequence text, Message msg)

public void setButton2 (CharSequence text, DialogInterface.OnClickListener listener)

Set a listener to be invoked when button 2 of the dialog is pressed.

Parameters
text The text to display in button 2.
listener The DialogInterface.OnClickListener to use.

public void setButton3 (CharSequence text, Message msg)

public void setButton3 (CharSequence text, DialogInterface.OnClickListener listener)

Set a listener to be invoked when button 3 of the dialog is pressed.

Parameters
text The text to display in button 3.
listener The DialogInterface.OnClickListener to use.

public void setCustomTitle (View customTitleView)

public void setIcon (Drawable icon)

public void setIcon (int resId)

Set resId to 0 if you don't want an icon.

Parameters
resId the resourceId of the drawable to use as the icon or 0 if you don't want an icon.

public void setInverseBackgroundForced (boolean forceInverseBackground)

public void setMessage (CharSequence message)

public void setTitle (CharSequence title)

Set the title text for this dialog's window.

Parameters
title The new text to display in the title.

public void setView (View view)

Set the view to display in that dialog.

Protected Methods

protected void onCreate (Bundle savedInstanceState)

Similar to onCreate(Bundle), you should initialized your dialog in this method, including calling setContentView(View).

Parameters
savedInstanceState If this dialog is being reinitalized after a the hosting activity was previously shut down, holds the result from the most recent call to onSaveInstanceState(), or null if this is the first time.