1 page.title= 2 page.tags=alertdialog,dialogfragment 3 4 @jd:body 5 6 7 8 <div id="qv-wrapper"> 9 <div id="qv"> 10 <h2> </h2> 11 <ol> 12 <li><a href="#DialogFragment"> </a></li> 13 <li><a href="#AlertDialog"> </a> 14 <ol> 15 <li><a href="#AddingButtons"> </a></li> 16 <li><a href="#AddingAList"> </a></li> 17 <li><a href="#CustomLayout"> </a></li> 18 </ol> 19 </li> 20 <li><a href="#PassingEvents"> </a></li> 21 <li><a href="#ShowingADialog"> </a></li> 22 <li><a href="#FullscreenDialog"> </a> 23 <ol> 24 <li><a href="#ActivityAsDialog"> </a></li> 25 </ol> 26 </li> 27 <li><a href="#DismissingADialog"> </a></li> 28 </ol> 29 30 <h2>Key </h2> 31 <ol> 32 <li>{@link android.app.DialogFragment}</li> 33 <li>{@link android.app.AlertDialog}</li> 34 </ol> 35 36 <h2> </h2> 37 <ol> 38 <li><a href="{@docRoot}design/building-blocks/dialogs.html"> </a></li> 39 <li><a href="{@docRoot}guide/topics/ui/controls/pickers.html"></a>(/ )</li> 40 </ol> 41 </div> 42 </div> 43 44 <p> 45 . 46 .</p> 47 48 <div class="note design"> 49 <p><strong> </strong></p> 50 <p> 51 <a href="{@docRoot}design/building-blocks/dialogs.html"></a> .</p> 52 </div> 53 54 <img src="{@docRoot}images/ui/dialogs.png" /> 55 56 <p>{@link android.app.Dialog} , 57 {@link android.app.Dialog} . 58 .</p> 59 <dl> 60 <dt>{@link android.app.AlertDialog}</dt> 61 <dd> , , 62 .</dd> 63 <dt>{@link android.app.DatePickerDialog} {@link android.app.TimePickerDialog}</dt> 64 <dd> UI .</dd> 65 </dl> 66 67 <div class="sidebox"> 68 <h2>ProgressDialog </h2> 69 <p>Android 70 {@link android.app.ProgressDialog} . . , 71 <a href="{@docRoot}design/building-blocks/progress.html"> 72 </a> , 73 {@link android.widget.ProgressBar} .</p> 74 </div> 75 76 <p> , 77 {@link android.support.v4.app.DialogFragment} . 78 {@link android.support.v4.app.DialogFragment} 79 . 80 {@link android.app.Dialog} .</p> 81 82 <p> {@link android.support.v4.app.DialogFragment} 83 <em></em> 84 . {@link 85 android.support.v4.app.DialogFragment} UI UI 86 . {@link 87 android.support.v4.app.Fragment} ( UI 88 ).</p> 89 90 <p> {@link 91 android.support.v4.app.DialogFragment} {@link android.app.AlertDialog} 92 . , 93 <a href="{@docRoot}guide/topics/ui/controls/pickers.html"></a> .</p> 94 95 <p class="note"><strong>:</strong> 96 {@link android.app.DialogFragment} 97 Android 3.0(API 11) <a href="{@docRoot}tools/support-library/index.html"> </a> {@link 98 android.support.v4.app.DialogFragment} . Android 1.6 99 {@link android.support.v4.app.DialogFragment} 100 API . 101 API 11 , {@link 102 android.app.DialogFragment} , 103 API . 104 <code>android.support.v4.app.DialogFragment</code> 105 . <code>android.app.DialogFragment</code> <em></em>.</p> 106 107 108 <h2 id="DialogFragment"> </h2> 109 110 <p> . 111 <a href="{@docRoot}design/building-blocks/dialogs.html"></a> 112 . 113 {@link android.support.v4.app.DialogFragment} {@link android.support.v4.app.DialogFragment#onCreateDialog 114 onCreateDialog()} {@link android.app.AlertDialog} 115 .</p> 116 117 <p> {@link android.app.AlertDialog}, 118 {@link android.support.v4.app.DialogFragment} .</p> 119 120 <pre> 121 public class FireMissilesDialogFragment extends DialogFragment { 122 @Override 123 public Dialog onCreateDialog(Bundle savedInstanceState) { 124 // Use the Builder class for convenient dialog construction 125 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 126 builder.setMessage(R.string.dialog_fire_missiles) 127 .setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() { 128 public void onClick(DialogInterface dialog, int id) { 129 // FIRE ZE MISSILES! 130 } 131 }) 132 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 133 public void onClick(DialogInterface dialog, int id) { 134 // User cancelled the dialog 135 } 136 }); 137 // Create the AlertDialog object and return it 138 return builder.create(); 139 } 140 } 141 </pre> 142 143 <div class="figure" style="width:290px;margin:0 0 0 20px"> 144 <img src="{@docRoot}images/ui/dialog_buttons.png" alt="" /> 145 <p class="img-caption"><strong> 1.</strong> 146 .</p> 147 </div> 148 149 <p> {@link 150 android.support.v4.app.DialogFragment#show show()} 151 1 .</p> 152 153 <p> {@link android.app.AlertDialog.Builder} 154 API .</p> 155 156 <p> 157 {@link android.support.v4.app.DialogFragment} . 158 <a href="{@docRoot}guide/components/fragments.html#Lifecycle"> </a> . 159 160 161 162 163 164 <h2 id="AlertDialog"> </h2> 165 166 167 <p>{@link android.app.AlertDialog} 168 , . 169 2 .</p> 170 171 <div class="figure" style="width:311px;margin-top:0"> 172 <img src="{@docRoot}images/ui/dialogs_regions.png" alt="" style="margin-bottom:0" /> 173 <p class="img-caption"><strong> 2.</strong> .</p> 174 </div> 175 176 <ol> 177 <li><b></b> 178 <p> , 179 . 180 ( 1 ) , .</li> 181 <li><b> </b> 182 <p> , .</p></li> 183 <li><b> </b> 184 <p> .</p></li> 185 </ol> 186 187 <p>{@link android.app.AlertDialog.Builder} 188 {@link android.app.AlertDialog} 189 API , .</p> 190 191 <p>{@link android.app.AlertDialog} .</p> 192 193 <pre> 194 <b>// 1. Instantiate an {@link android.app.AlertDialog.Builder} with its constructor</b> 195 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 196 197 <b>// 2. Chain together various setter methods to set the dialog characteristics</b> 198 builder.setMessage(R.string.dialog_message) 199 .setTitle(R.string.dialog_title); 200 201 <b>// 3. Get the {@link android.app.AlertDialog} from {@link android.app.AlertDialog.Builder#create()}</b> 202 AlertDialog dialog = builder.create(); 203 </pre> 204 205 <p> 206 {@link android.app.AlertDialog.Builder} .</p> 207 208 209 210 211 <h3 id="AddingButtons"> </h3> 212 213 <p> 2 214 {@link android.app.AlertDialog.Builder#setPositiveButton setPositiveButton()} 215 {@link android.app.AlertDialog.Builder#setNegativeButton setNegativeButton()} .</p> 216 217 <pre style="clear:right"> 218 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 219 // Add the buttons 220 builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 221 public void onClick(DialogInterface dialog, int id) { 222 // User clicked OK button 223 } 224 }); 225 builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 226 public void onClick(DialogInterface dialog, int id) { 227 // User cancelled the dialog 228 } 229 }); 230 // Set other dialog properties 231 ... 232 233 // Create the AlertDialog 234 AlertDialog dialog = builder.create(); 235 </pre> 236 237 <p><code>set...Button()</code> ( 238 <a href="{@docRoot}guide/topics/resources/string-resource.html"> </a> ), 239 {@link android.content.DialogInterface.OnClickListener} 240 .</p> 241 242 <p> .</p> 243 <dl> 244 <dt></dt> 245 <dd> ("(OK)" ).</dd> 246 <dt></dt> 247 <dd> .</dd> 248 <dt></dt> 249 <dd> 250 . . 251 " " .</dd> 252 </dl> 253 254 <p>{@link 255 android.app.AlertDialog} . , "" .</p> 256 257 258 259 <div class="figure" style="width:290px;margin:0 0 0 40px"> 260 <img src="{@docRoot}images/ui/dialog_list.png" alt="" /> 261 <p class="img-caption"><strong> 3.</strong> 262 .</p> 263 </div> 264 265 <h3 id="AddingAList"> </h3> 266 267 <p>{@link android.app.AlertDialog} API .</p> 268 <ul> 269 <li> </li> 270 <li> ( )</li> 271 <li> ()</li> 272 </ul> 273 274 <p> 3 275 {@link android.app.AlertDialog.Builder#setItems setItems()} .</p> 276 277 <pre style="clear:right"> 278 @Override 279 public Dialog onCreateDialog(Bundle savedInstanceState) { 280 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 281 builder.setTitle(R.string.pick_color) 282 .setItems(R.array.colors_array, new DialogInterface.OnClickListener() { 283 public void onClick(DialogInterface dialog, int which) { 284 // The 'which' argument contains the index position 285 // of the selected item 286 } 287 }); 288 return builder.create(); 289 } 290 </pre> 291 292 <p> , 293 . 294 {@link android.app.AlertDialog.Builder#setTitle setTitle()} . 295 {@link 296 android.app.AlertDialog.Builder#setItems setItems()} . 297 {@link 298 android.app.AlertDialog.Builder#setAdapter setAdapter()} . (: ) 299 {@link android.widget.ListAdapter} .</p> 300 301 <p>{@link android.widget.ListAdapter} , 302 {@link android.support.v4.content.Loader} 303 . 304 <a href="{@docRoot}guide/topics/ui/declaring-layout.html#AdapterViews"> 305 </a> <a href="{@docRoot}guide/components/loaders.html"></a> 306 .</p> 307 308 <p class="note"><strong>:</strong> . 309 .</p> 310 311 <div class="figure" style="width:290px;margin:-30px 0 0 40px"> 312 <img src="{@docRoot}images/ui/dialog_checkboxes.png" /> 313 <p class="img-caption"><strong> 4.</strong> 314 .</p> 315 </div> 316 317 318 <h4 id="Checkboxes"> </h4> 319 320 <p> () 321 ( ), 322 {@link android.app.AlertDialog.Builder#setMultiChoiceItems(Cursor,String,String, 323 DialogInterface.OnMultiChoiceClickListener) setMultiChoiceItems()} 324 {@link android.app.AlertDialog.Builder#setSingleChoiceItems(int,int,DialogInterface.OnClickListener) 325 setSingleChoiceItems()} .</p> 326 327 <p> 4 . 328 329 {@link java.util.ArrayList} .</p> 330 331 <pre style="clear:right"> 332 @Override 333 public Dialog onCreateDialog(Bundle savedInstanceState) { 334 mSelectedItems = new ArrayList(); // Where we track the selected items 335 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 336 // Set the dialog title 337 builder.setTitle(R.string.pick_toppings) 338 // Specify the list array, the items to be selected by default (null for none), 339 // and the listener through which to receive callbacks when items are selected 340 .setMultiChoiceItems(R.array.toppings, null, 341 new DialogInterface.OnMultiChoiceClickListener() { 342 @Override 343 public void onClick(DialogInterface dialog, int which, 344 boolean isChecked) { 345 if (isChecked) { 346 // If the user checked the item, add it to the selected items 347 mSelectedItems.add(which); 348 } else if (mSelectedItems.contains(which)) { 349 // Else, if the item is already in the array, remove it 350 mSelectedItems.remove(Integer.valueOf(which)); 351 } 352 } 353 }) 354 // Set the action buttons 355 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 356 @Override 357 public void onClick(DialogInterface dialog, int id) { 358 // User clicked OK, so save the mSelectedItems results somewhere 359 // or return them to the component that opened the dialog 360 ... 361 } 362 }) 363 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 364 @Override 365 public void onClick(DialogInterface dialog, int id) { 366 ... 367 } 368 }); 369 370 return builder.create(); 371 } 372 </pre> 373 374 <p> " " 375 , {@link 376 android.app.AlertDialog.Builder#setSingleChoiceItems(int,int,DialogInterface.OnClickListener) 377 setSingleChoiceItems()} . 378 , , 379 .</p> 380 381 382 383 384 385 <h3 id="CustomLayout"> </h3> 386 387 <div class="figure" style="width:290px;margin:-30px 0 0 40px"> 388 <img src="{@docRoot}images/ui/dialog_custom.png" alt="" /> 389 <p class="img-caption"><strong> 5.</strong> .</p> 390 </div> 391 392 <p> , 393 {@link android.app.AlertDialog} . {@link 394 android.app.AlertDialog.Builder#setView setView()} on your {@link 395 android.app.AlertDialog.Builder} .</p> 396 397 <p> , 398 {@link android.app.AlertDialog.Builder} .</p> 399 400 <p> 5 .</p> 401 402 <p style="clear:right" class="code-caption">res/layout/dialog_signin.xml</p> 403 <pre> 404 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 405 android:orientation="vertical" 406 android:layout_width="wrap_content" 407 android:layout_height="wrap_content"> 408 <ImageView 409 android:src="@drawable/header_logo" 410 android:layout_width="match_parent" 411 android:layout_height="64dp" 412 android:scaleType="center" 413 android:background="#FFFFBB33" 414 android:contentDescription="@string/app_name" /> 415 <EditText 416 android:id="@+id/username" 417 android:inputType="textEmailAddress" 418 android:layout_width="match_parent" 419 android:layout_height="wrap_content" 420 android:layout_marginTop="16dp" 421 android:layout_marginLeft="4dp" 422 android:layout_marginRight="4dp" 423 android:layout_marginBottom="4dp" 424 android:hint="@string/username" /> 425 <EditText 426 android:id="@+id/password" 427 android:inputType="textPassword" 428 android:layout_width="match_parent" 429 android:layout_height="wrap_content" 430 android:layout_marginTop="4dp" 431 android:layout_marginLeft="4dp" 432 android:layout_marginRight="4dp" 433 android:layout_marginBottom="16dp" 434 android:fontFamily="sans-serif" 435 android:hint="@string/password"/> 436 </LinearLayout> 437 </pre> 438 439 <p class="note"><strong>:</strong> {@link android.widget.EditText} 440 {@code "textPassword"} , 441 {@code "sans-serif"} . 442 .</p> 443 444 <p>{@link android.support.v4.app.DialogFragment} , 445 {@link android.view.LayoutInflater} 446 {@link android.app.Activity#getLayoutInflater()} 447 {@link android.view.LayoutInflater#inflate inflate()} . 448 ID . 449 {@link android.app.AlertDialog#setView setView()} 450 .</p> 451 452 <pre> 453 @Override 454 public Dialog onCreateDialog(Bundle savedInstanceState) { 455 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 456 // Get the layout inflater 457 LayoutInflater inflater = getActivity().getLayoutInflater(); 458 459 // Inflate and set the layout for the dialog 460 // Pass null as the parent view because its going in the dialog layout 461 builder.setView(inflater.inflate(R.layout.dialog_signin, null)) 462 // Add action buttons 463 .setPositiveButton(R.string.signin, new DialogInterface.OnClickListener() { 464 @Override 465 public void onClick(DialogInterface dialog, int id) { 466 // sign in the user ... 467 } 468 }) 469 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 470 public void onClick(DialogInterface dialog, int id) { 471 LoginDialogFragment.this.getDialog().cancel(); 472 } 473 }); 474 return builder.create(); 475 } 476 </pre> 477 478 <div class="note"> 479 <p><strong>:</strong> , 480 {@link android.app.Activity} . 481 {@link android.app.Dialog} API . <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code 482 <activity>}</a> 483 {@link android.R.style#Theme_Holo_Dialog Theme.Holo.Dialog} 484 .</p> 485 486 <pre> 487 <activity android:theme="@android:style/Theme.Holo.Dialog" > 488 </pre> 489 <p>. .</p> 490 </div> 491 492 493 494 <h2 id="PassingEvents"> </h2> 495 496 <p> , 497 {@link android.support.v4.app.DialogFragment} 498 . 499 . 500 501 .</p> 502 503 <p> {@link android.support.v4.app.DialogFragment}. 504 .</p> 505 506 <pre> 507 public class NoticeDialogFragment extends DialogFragment { 508 509 /* The activity that creates an instance of this dialog fragment must 510 * implement this interface in order to receive event callbacks. 511 * Each method passes the DialogFragment in case the host needs to query it. */ 512 public interface NoticeDialogListener { 513 public void onDialogPositiveClick(DialogFragment dialog); 514 public void onDialogNegativeClick(DialogFragment dialog); 515 } 516 517 // Use this instance of the interface to deliver action events 518 NoticeDialogListener mListener; 519 520 // Override the Fragment.onAttach() method to instantiate the NoticeDialogListener 521 @Override 522 public void onAttach(Activity activity) { 523 super.onAttach(activity); 524 // Verify that the host activity implements the callback interface 525 try { 526 // Instantiate the NoticeDialogListener so we can send events to the host 527 mListener = (NoticeDialogListener) activity; 528 } catch (ClassCastException e) { 529 // The activity doesn't implement the interface, throw exception 530 throw new ClassCastException(activity.toString() 531 + " must implement NoticeDialogListener"); 532 } 533 } 534 ... 535 } 536 </pre> 537 538 <p> . 539 , 540 {@code NoticeDialogListener} .</p> 541 542 <pre> 543 public class MainActivity extends FragmentActivity 544 implements NoticeDialogFragment.NoticeDialogListener{ 545 ... 546 547 public void showNoticeDialog() { 548 // Create an instance of the dialog fragment and show it 549 DialogFragment dialog = new NoticeDialogFragment(); 550 dialog.show(getSupportFragmentManager(), "NoticeDialogFragment"); 551 } 552 553 // The dialog fragment receives a reference to this Activity through the 554 // Fragment.onAttach() callback, which it uses to call the following methods 555 // defined by the NoticeDialogFragment.NoticeDialogListener interface 556 @Override 557 public void onDialogPositiveClick(DialogFragment dialog) { 558 // User touched the dialog's positive button 559 ... 560 } 561 562 @Override 563 public void onDialogNegativeClick(DialogFragment dialog) { 564 // User touched the dialog's negative button 565 ... 566 } 567 } 568 </pre> 569 570 <p> {@code NoticeDialogListener} — {@link android.support.v4.app.Fragment#onAttach onAttach()} 571 — 572 573 .</p> 574 575 <pre> 576 public class NoticeDialogFragment extends DialogFragment { 577 ... 578 579 @Override 580 public Dialog onCreateDialog(Bundle savedInstanceState) { 581 // Build the dialog and set up the button click handlers 582 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 583 builder.setMessage(R.string.dialog_fire_missiles) 584 .setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() { 585 public void onClick(DialogInterface dialog, int id) { 586 // Send the positive button event back to the host activity 587 mListener.onDialogPositiveClick(NoticeDialogFragment.this); 588 } 589 }) 590 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 591 public void onClick(DialogInterface dialog, int id) { 592 // Send the negative button event back to the host activity 593 mListener.onDialogNegativeClick(NoticeDialogFragment.this); 594 } 595 }); 596 return builder.create(); 597 } 598 } 599 </pre> 600 601 602 603 <h2 id="ShowingADialog"> </h2> 604 605 <p> , {@link 606 android.support.v4.app.DialogFragment} {@link android.support.v4.app.DialogFragment#show 607 show()} {@link android.support.v4.app.FragmentManager} 608 .</p> 609 610 <p>{@link android.support.v4.app.FragmentManager} 611 {@link android.support.v4.app.FragmentActivity} 612 {@link android.support.v4.app.FragmentActivity#getSupportFragmentManager()} {@link 613 android.support.v4.app.Fragment} {@link 614 android.support.v4.app.Fragment#getFragmentManager()} . :</p> 615 616 <pre> 617 public void confirmFireMissiles() { 618 DialogFragment newFragment = new FireMissilesDialogFragment(); 619 newFragment.show(getSupportFragmentManager(), "missiles"); 620 } 621 </pre> 622 623 <p> {@code "missiles"} 624 . {@link android.support.v4.app.FragmentManager#findFragmentByTag 625 findFragmentByTag()} . 626 </p> 627 628 629 630 631 <h2 id="FullscreenDialog"> </h2> 632 633 <p>UI , UI 634 635 ( ). {@link android.support.v4.app.DialogFragment} 636 {@link 637 android.support.v4.app.Fragment} .</p> 638 639 <p> {@link android.app.AlertDialog.Builder AlertDialog.Builder} 640 {@link android.app.Dialog} . 641 {@link android.support.v4.app.DialogFragment} , 642 UI . 643 {@link android.support.v4.app.DialogFragment#onCreateView 644 onCreateView()} .</p> 645 646 <p> 647 {@link android.support.v4.app.DialogFragment} (<code>purchase_items.xml</code> ).</p> 648 649 <pre> 650 public class CustomDialogFragment extends DialogFragment { 651 /** The system calls this to get the DialogFragment's layout, regardless 652 of whether it's being displayed as a dialog or an embedded fragment. */ 653 @Override 654 public View onCreateView(LayoutInflater inflater, ViewGroup container, 655 Bundle savedInstanceState) { 656 // Inflate the layout to use as dialog or embedded fragment 657 return inflater.inflate(R.layout.purchase_items, container, false); 658 } 659 660 /** The system calls this only when creating the layout in a dialog. */ 661 @Override 662 public Dialog onCreateDialog(Bundle savedInstanceState) { 663 // The only reason you might override this method when using onCreateView() is 664 // to modify any dialog characteristics. For example, the dialog includes a 665 // title by default, but your custom layout might not need it. So here you can 666 // remove the dialog title, but you must call the superclass to get the Dialog. 667 Dialog dialog = super.onCreateDialog(savedInstanceState); 668 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 669 return dialog; 670 } 671 } 672 </pre> 673 674 <p> UI . 675 </p> 676 677 <pre> 678 public void showDialog() { 679 FragmentManager fragmentManager = getSupportFragmentManager(); 680 CustomDialogFragment newFragment = new CustomDialogFragment(); 681 682 if (mIsLargeLayout) { 683 // The device is using a large layout, so show the fragment as a dialog 684 newFragment.show(fragmentManager, "dialog"); 685 } else { 686 // The device is smaller, so show the fragment fullscreen 687 FragmentTransaction transaction = fragmentManager.beginTransaction(); 688 // For a little polish, specify a transition animation 689 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 690 // To make it fullscreen, use the 'content' root view as the container 691 // for the fragment, which is always the root view for the activity 692 transaction.add(android.R.id.content, newFragment) 693 .addToBackStack(null).commit(); 694 } 695 } 696 </pre> 697 698 <p> 699 <a href="{@docRoot}guide/components/fragments.html"></a> .</p> 700 701 <p> <code>mIsLargeLayout</code> 702 ( ). 703 704 <a href="{@docRoot}guide/topics/resources/more-resources.html#Bool"> </a> 705 <a href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources"> </a> . 706 .</p> 707 708 <p class="code-caption">res/values/bools.xml</p> 709 <pre> 710 <!-- Default boolean values --> 711 <resources> 712 <bool name="large_layout">false</bool> 713 </resources> 714 </pre> 715 716 <p class="code-caption">res/values-large/bools.xml</p> 717 <pre> 718 <!-- Large screen boolean values --> 719 <resources> 720 <bool name="large_layout">true</bool> 721 </resources> 722 </pre> 723 724 <p> 725 {@link android.app.Activity#onCreate onCreate()} {@code mIsLargeLayout} .</p> 726 727 <pre> 728 boolean mIsLargeLayout; 729 730 @Override 731 public void onCreate(Bundle savedInstanceState) { 732 super.onCreate(savedInstanceState); 733 setContentView(R.layout.activity_main); 734 735 mIsLargeLayout = getResources().getBoolean(R.bool.large_layout); 736 } 737 </pre> 738 739 740 741 <h3 id="ActivityAsDialog"> </h3> 742 743 <p> UI , 744 {@link android.app.Activity} . 745 , 746 747 748 .</p> 749 750 <p> , 751 {@link android.R.style#Theme_Holo_DialogWhenLarge Theme.Holo.DialogWhenLarge} 752 <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code 753 <activity>}</a> .</p> 754 755 <pre> 756 <activity android:theme="@android:style/Theme.Holo.DialogWhenLarge" > 757 </pre> 758 759 <p> <a href="{@docRoot}guide/topics/ui/themes.html"> </a> .</p> 760 761 762 763 <h2 id="DismissingADialog"> </h2> 764 765 <p> 766 {@link android.app.AlertDialog.Builder} .</p> 767 768 <p> . 769 . 770 . {@link 771 android.support.v4.app.DialogFragment} {@link android.support.v4.app.DialogFragment#dismiss()} .</p> 772 773 <p> 774 , {@link 775 android.support.v4.app.DialogFragment} @link 776 android.support.v4.app.DialogFragment#onDismiss onDismiss()} .</p> 777 778 <p> <em></em> . 779 . 780 <em></em> , 781 {@link 782 android.app.Dialog} {@link android.app.Dialog#cancel()} (: "" ).</p> 783 784 <p> {@link 785 android.support.v4.app.DialogFragment} 786 {@link android.support.v4.app.DialogFragment#onCancel onCancel()} .</p> 787 788 <p class="note"><strong>:</strong> 789 {@link android.support.v4.app.DialogFragment#onCancel onCancel()} 790 {@link android.support.v4.app.DialogFragment#onDismiss onDismiss()} . 791 {@link android.app.Dialog#dismiss Dialog.dismiss()} {@link 792 android.support.v4.app.DialogFragment#dismiss DialogFragment.dismiss()} 793 {@link android.support.v4.app.DialogFragment#onDismiss onDismiss()} {@link android.support.v4.app.DialogFragment#onCancel onCancel()} 794 <em></em>. 795 <em></em> , {@link android.support.v4.app.DialogFragment#dismiss dismiss()} 796 .</p> 797 798 799