Home | History | Annotate | Download | only in ui
      1 page.title=
      2 parent.title= 
      3 parent.link=index.html
      4 @jd:body
      5 
      6 <div id="qv-wrapper">
      7 <div id="qv">
      8   <h2>  </h2>
      9 <ol>
     10   <li><a href="#xml">XML  </a></li>
     11   <li><a href="#options-menu">  </a>
     12     <ol>
     13       <li><a href="#RespondingOptionsMenu">  </a></li>
     14       <li><a href="#ChangingTheMenu">   </a></li>
     15     </ol>
     16   </li>
     17   <li><a href="#context-menu">  </a>
     18     <ol>
     19       <li><a href="#FloatingContextMenu">   </a></li>
     20       <li><a href="#CAB">   </a></li>
     21     </ol>
     22   </li>
     23   <li><a href="#PopupMenu">  </a>
     24     <ol>
     25       <li><a href="#PopupEvents">  </a></li>
     26     </ol>
     27   </li>
     28   <li><a href="#groups">  </a>
     29     <ol>
     30       <li><a href="#checkable">    </a></li>
     31     </ol>
     32   </li>
     33   <li><a href="#intents">    </a>
     34     <ol>
     35       <li><a href="#AllowingToAdd">    </a></li>
     36     </ol>
     37   </li>
     38 </ol>
     39 
     40   <h2>Key </h2>
     41   <ol>
     42     <li>{@link android.view.Menu}</li>
     43     <li>{@link android.view.MenuItem}</li>
     44     <li>{@link android.view.ContextMenu}</li>
     45     <li>{@link android.view.ActionMode}</li>
     46   </ol>
     47 
     48   <h2> </h2>
     49   <ol>
     50     <li><a href="{@docRoot}guide/topics/ui/actionbar.html"> </a></li>
     51     <li><a href="{@docRoot}guide/topics/resources/menu-resource.html"> </a></li>
     52     <li><a href="http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html">
     53    </a></li>
     54   </ol>
     55 </div>
     56 </div>
     57 
     58 <p>         .  
     59           {@link android.view.Menu} API
     60  .</p>
     61 
     62 <p>Android 3.0(API  11) Android  
     63  <em></em>    .    Android 
     64  6       
     65    .</p>
     66 
     67 <p>      ,    
     68     {@link android.view.Menu} API  .  
     69   Android       
     70   .</p>
     71 
     72 <dl>
     73   <dt><strong>    </strong></dt>
     74     <dd><a href="#options-menu"> </a>      
     75 . 
     76  "", " "  ""        .
     77   <p>Android 2.3     
     78 <em></em>        .</p>
     79   <p>Android 3.0  ,    <a href="{@docRoot}guide/topics/ui/actionbar.html"> </a>      
     80 . Android 3.0 <em></em>   (
     81 
     82   ),        
     83   .</p>
     84   <p><a href="#options-menu">  </a>  .</p>
     85     </dd>
     86     
     87   <dt><strong>     </strong></dt>
     88   
     89    <dd>       <a href="#FloatingContextMenu"> </a>
     90 .     
     91    .
     92   <p>Android 3.0    , <a href="#CAB">  </a>      .  
     93            
     94     .</p>
     95   <p><a href="#context-menu">  </a>   .</p>
     96 </dd>
     97     
     98   <dt><strong> </strong></dt>
     99     <dd>         
    100 .        
    101         .   
    102      <strong> </strong>.    .
    103         
    104    .
    105   <p><a href="#PopupMenu">  </a>  .</p>
    106 </dd>
    107 </dl>
    108 
    109 
    110 
    111 <h2 id="xml">XML  </h2>
    112 
    113 <p>   , Android  XML    .
    114     
    115 XML <a href="{@docRoot}guide/topics/resources/menu-resource.html"> </a>     .  
    116       ({@link android.view.Menu}   ).
    117 </p>
    118 
    119 <p>            .</p>
    120 <ul>
    121   <li>  XML    .</li>
    122   <li>     .</li>
    123   <li><a href="{@docRoot}guide/topics/resources/index.html"> </a>     ,      
    124      .</li>
    125 </ul>
    126 
    127 <p>   <code>res/menu/</code>
    128  XML      .</p>
    129 <dl>
    130   <dt><code>&lt;menu></code></dt>
    131     <dd>   {@link android.view.Menu} . 
    132 <code>&lt;menu></code>       
    133 <code>&lt;item></code> <code>&lt;group></code>    .</dd>
    134 
    135   <dt><code>&lt;item></code></dt>
    136     <dd>     {@link android.view.MenuItem} . 
    137         <code>&lt;menu></code>    .</dd>
    138     
    139   <dt><code>&lt;group></code></dt>
    140     <dd>{@code &lt;item&gt;}     .          
    141    . 
    142    <a href="#groups">  </a> .</dd>
    143 </dl>
    144 
    145 
    146 <p> <code>game_menu.xml</code>  .</p>
    147 <pre>
    148 &lt;?xml version="1.0" encoding="utf-8"?&gt;
    149 &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    150     &lt;item android:id="@+id/new_game"
    151           android:icon="@drawable/ic_new_game"
    152           android:title="@string/new_game"
    153           android:showAsAction="ifRoom"/&gt;
    154     &lt;item android:id="@+id/help"
    155           android:icon="@drawable/ic_help"
    156           android:title="@string/help" /&gt;
    157 &lt;/menu&gt;
    158 </pre>
    159 
    160 <p><code>&lt;item></code>    
    161        .       .</p>
    162 
    163 <dl>
    164   <dt>{@code android:id}</dt>
    165     <dd>   ID.   
    166        .</dd>
    167   <dt>{@code android:icon}</dt>
    168     <dd>       .</dd>
    169   <dt>{@code android:title}</dt>
    170     <dd>     .</dd>
    171   <dt>{@code android:showAsAction}</dt>
    172     <dd><a href="{@docRoot}guide/topics/ui/actionbar.html"> </a>      .</dd>
    173 </dl>
    174 
    175 <p>       ,       .
    176      <a href="{@docRoot}guide/topics/resources/menu-resource.html"> </a>  .</p>
    177 
    178 <p>{@code &lt;menu&gt;} 
    179 {@code &lt;item&gt;}          (  ).    PC   (,
    180 ,  )         
    181 . :</p>
    182 
    183 <pre>
    184 &lt;?xml version="1.0" encoding="utf-8"?&gt;
    185 &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    186     &lt;item android:id="@+id/file"
    187           android:title="@string/file" &gt;
    188         &lt;!-- "file" submenu --&gt;
    189         &lt;menu&gt;
    190             &lt;item android:id="@+id/create_new"
    191                   android:title="@string/create_new" /&gt;
    192             &lt;item android:id="@+id/open"
    193                   android:title="@string/open" /&gt;
    194         &lt;/menu&gt;
    195     &lt;/item&gt;
    196 &lt;/menu&gt;
    197 </pre>
    198 
    199 <p>  
    200 {@link android.view.MenuInflater#inflate(int,Menu)
    201 MenuInflater.inflate()}     (XML     ).      
    202    .</p>
    203 
    204 
    205 
    206 <h2 id="options-menu">  </h2>
    207 
    208 <div class="figure" style="width:200px;margin:0">
    209   <img src="{@docRoot}images/options_menu.png" height="333" alt="" />
    210   <p class="img-caption"><strong> 1.</strong> Android 2.3  
    211   .</p>
    212 </div>
    213 
    214 <p>  "", " "  "" 
    215          .</p>
    216 
    217 <p>     
    218       .</p>
    219 
    220 <ul>
    221   <li><strong>Android 2.3.x(API  10)
    222 </strong>   ,
    223  1   <em></em>        .        
    224 
    225 ,       .        , Android 
    226        .   
    227 <em></em>    .</li>
    228 
    229   <li><strong>Android 3.0(API  11)
    230 </strong>   ,    <a href="{@docRoot}guide/topics/ui/actionbar.html"> </a>   .       .
    231     
    232       (      <em></em>   ). 
    233     
    234  
    235 {@code android:showAsAction="ifRoom"}  {@code &lt;item&gt;}          (
    236 2 ). <p>         <a href="{@docRoot}guide/topics/ui/actionbar.html"> </a>  . </p>
    237 <p class="note"><strong>:</strong> Andoid 3.0    <em></em> 
    238           .  ,
    239    Android     <a href="{@docRoot}resources/samples/ActionBarCompat/index.html">  </a>
    240  .</p>
    241 </li>
    242 </ul>
    243 
    244 <img src="{@docRoot}images/ui/actionbar.png" alt="" />
    245 <p class="img-caption"><strong> 2.</strong> <a href="{@docRoot}resources/samples/HoneycombGallery/index.html">Honeycomb </a>   
    246     (   ) .</p>
    247 
    248 <p>{@link android.app.Activity}
    249   {@link android.app.Fragment}        .   
    250     ,  UI .    , 
    251             
    252 .      {@code &lt;item&gt;}{@code android:orderInCategory}  
    253      .</p>
    254 
    255 <p>     {@link
    256 android.app.Activity#onCreateOptionsMenu(Menu) onCreateOptionsMenu()} ( 
    257  {@link android.app.Fragment#onCreateOptionsMenu onCreateOptionsMenu()}  ).  
    258 (<a href="#xml">XML </a>)     {@link
    259 android.view.Menu}   . :</p>
    260 
    261 <pre>
    262 &#64;Override
    263 public boolean onCreateOptionsMenu(Menu menu) {
    264     MenuInflater inflater = {@link android.app.Activity#getMenuInflater()};
    265     inflater.inflate(R.menu.game_menu, menu);
    266     return true;
    267 }
    268 </pre>
    269 
    270 <p>, {@link android.view.Menu#add(int,int,int,int)
    271 add()}     {@link android.view.Menu#findItem findItem()}  
    272 {@link android.view.MenuItem} API    .</p>
    273 
    274 <p>Android 2.3.x     ,       {@link
    275 android.app.Activity#onCreateOptionsMenu(Menu) onCreateOptionsMenu()}
    276 . Android 3.0    ,
    277          {@link android.app.Activity#onCreateOptionsMenu(Menu) onCreateOptionsMenu()}
    278 .</p>
    279 
    280 
    281 
    282 <h3 id="RespondingOptionsMenu">  </h3>
    283 
    284 <p>    (    ),
    285   {@link android.app.Activity#onOptionsItemSelected(MenuItem)
    286 onOptionsItemSelected()}  .    {@link android.view.MenuItem} .   
    287 {@link android.view.MenuItem#getItemId()}  .  (  {@code android:id}  
    288 {@link android.view.Menu#add(int,int,int,int) add()}    )     ID 
    289 .  ID
    290         . :</p>
    291 
    292 <pre>
    293 &#64;Override
    294 public boolean onOptionsItemSelected(MenuItem item) {
    295     // Handle item selection
    296     switch (item.getItemId()) {
    297         case R.id.new_game:
    298             newGame();
    299             return true;
    300         case R.id.help:
    301             showHelp();
    302             return true;
    303         default:
    304             return super.onOptionsItemSelected(item);
    305     }
    306 }
    307 </pre>
    308 
    309 <p>    {@code true} .  
    310  , {@link
    311 android.app.Activity#onOptionsItemSelected(MenuItem) onOptionsItemSelected()}     (
    312  '' ).</p>
    313 
    314 <p>   ,   {@link
    315 android.app.Activity#onOptionsItemSelected(MenuItem) onOptionsItemSelected()} ,  
    316  
    317 {@code true}      (   )      .</p>
    318 
    319 <p class="note"><strong>:</strong> Android 3.0
    320 {@code android:onClick}   XML     -    . 
    321         . 
    322    {@link android.view.MenuItem}   .    
    323     .    <a href="{@docRoot}guide/topics/resources/menu-resource.html"> </a>  .</p>
    324 
    325 <p class="note"><strong>:</strong>     ,        ,
    326 
    327 {@link android.app.Activity#onCreateOptionsMenu(Menu)
    328 onCreateOptionsMenu()} {@link android.app.Activity#onOptionsItemSelected(MenuItem)
    329 onOptionsItemSelected()}         .             
    330  .           ,
    331      .
    332        ,
    333   {@link android.app.Activity#onCreateOptionsMenu(Menu)
    334 onCreateOptionsMenu()} . {@code super.onCreateOptionsMenu(menu)} 
    335    , {@link
    336 android.view.Menu#add(int,int,int,int) menu.add()}     .       
    337   .</p>
    338 
    339 
    340 <h3 id="ChangingTheMenu">   </h3>
    341 
    342 <p> {@link android.app.Activity#onCreateOptionsMenu(Menu)
    343 onCreateOptionsMenu()} ,   {@link android.view.Menu}  
    344     {@link android.app.Activity#onCreateOptionsMenu(Menu) onCreateOptionsMenu()}
    345  .  {@link
    346 android.app.Activity#onCreateOptionsMenu(Menu) onCreateOptionsMenu()} 
    347     ,       .</p>
    348 
    349 <p>    
    350     , 
    351 {@link android.app.Activity#onPrepareOptionsMenu(Menu) onPrepareOptionsMenu()}    . 
    352     {@link android.view.Menu}  ,
    353  , ,       ( {@link
    354 android.app.Fragment#onPrepareOptionsMenu onPrepareOptionsMenu()}  ).</p>
    355 
    356 <p>Android 2.3.x ,     (<em></em>
    357  ) {@link
    358 android.app.Activity#onPrepareOptionsMenu(Menu)
    359 onPrepareOptionsMenu()} .</p>
    360 
    361 <p>Android 3.0        
    362       .       ,
    363 {@link android.app.Activity#invalidateOptionsMenu invalidateOptionsMenu()} 
    364  {@link android.app.Activity#onPrepareOptionsMenu(Menu) onPrepareOptionsMenu()}   .</p>
    365 
    366 <p class="note"><strong>:</strong> 
    367     {@link android.view.View}   
    368       .  (  d-   ), 
    369           
    370      . {@link
    371 android.view.View}      , <a href="#context-menu"> </a> .</p>
    372 
    373 
    374 
    375 
    376 <h2 id="context-menu">  </h2>
    377 
    378 <div class="figure" style="width:420px;margin-top:-1em">
    379   <img src="{@docRoot}images/ui/menu-context.png" alt="" />
    380   <p class="img-caption"><strong> 3.</strong>   ()
    381    () .</p>
    382 </div>
    383 
    384 <p>  UI        .
    385       , {@link
    386 android.widget.ListView} {@link android.widget.GridView},         
    387    .</p>
    388 
    389 <p>      .</p>
    390 <ul>
    391   <li><a href="#FloatingContextMenu">  </a> .         
    392 ( )    
    393 .        
    394    .</li>
    395 
    396   <li><a href="#CAB">  </a> .              <em>  </em> 
    397 {@link android.view.ActionMode}  .
    398       
    399         (   ).</li>
    400 </ul>
    401 
    402 <p class="note"><strong>:</strong>    Android 3.0(API
    403  11)    ,         .
    404   3.0       
    405     .</p>
    406 
    407 
    408 <h3 id="FloatingContextMenu">   </h3>
    409 
    410 <p>      .</p>
    411 <ol>
    412   <li>    {@link android.view.View} .  
    413 {@link android.app.Activity#registerForContextMenu(View) registerForContextMenu()}   
    414 {@link android.view.View}  .
    415   <p> {@link android.widget.ListView}  {@link android.widget.GridView} 
    416         ,
    417 {@link android.widget.ListView} {@link android.widget.GridView} {@link
    418 android.app.Activity#registerForContextMenu(View) registerForContextMenu()}      .</p>
    419 </li>
    420 
    421   <li>{@link android.app.Activity} {@link android.app.Fragment} {@link
    422 android.view.View.OnCreateContextMenuListener#onCreateContextMenu onCreateContextMenu()}  
    423 .
    424   <p>  -  ,  {@link
    425 android.view.View.OnCreateContextMenuListener#onCreateContextMenu onCreateContextMenu()}
    426  .      .      . :
    427 </p>
    428 <pre>
    429 &#64;Override
    430 public void onCreateContextMenu(ContextMenu menu, View v,
    431                                 ContextMenuInfo menuInfo) {
    432     super.onCreateContextMenu(menu, v, menuInfo);
    433     MenuInflater inflater = getMenuInflater();
    434     inflater.inflate(R.menu.context_menu, menu);
    435 }
    436 </pre>
    437 
    438 <p>{@link android.view.MenuInflater}  <a href="{@docRoot}guide/topics/resources/menu-resource.html"> </a>    .  
    439    {@link android.view.View}
    440       {@link android.view.ContextMenu.ContextMenuInfo}  
    441 .             , 
    442         
    443   .</p>
    444 </li>
    445 
    446 <li>{@link android.app.Activity#onContextItemSelected(MenuItem)
    447 onContextItemSelected()} .
    448   <p>    ,    
    449    . :</p>
    450 
    451 <pre>
    452 &#64;Override
    453 public boolean onContextItemSelected(MenuItem item) {
    454     AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    455     switch (item.getItemId()) {
    456         case R.id.edit:
    457             editNote(info.id);
    458             return true;
    459         case R.id.delete:
    460             deleteNote(info.id);
    461             return true;
    462         default:
    463             return super.onContextItemSelected(item);
    464     }
    465 }
    466 </pre>
    467 
    468 <p>{@link android.view.MenuItem#getItemId()}     ID ,
    469 <a href="#xml">
    470 XML  </a>     {@code
    471 android:id}   XML      .</p>
    472 
    473 <p>    {@code true} .     , 
    474       .      
    475       .      
    476       .
    477 {@code true}  {@code false}   (   )     (
    478 {@link android.app.Activity} {@code android.app.Fragment}   {@code
    479 false}         ).</p>
    480 </li>
    481 </ol>
    482 
    483 
    484 <h3 id="CAB">   </h3>
    485 
    486 <p>          {@link android.view.ActionMode}
    487  .    
    488   , <em>  </em>   
    489         .  
    490     (   ),   ,  
    491  (   ).     , ''  
    492 
    493    <em></em>         .</p>
    494 
    495 <p class="note"><strong>:</strong>    
    496  <a href="{@docRoot}guide/topics/ui/actionbar.html"> </a>    .   
    497  .            
    498  .</p>
    499 
    500 <p>Android 3.0 (API level 11)    , 
    501      <a href="#FloatingContextMenu">  </a>    .</p>
    502 
    503 <p>    ,     (   )    
    504  .</p>
    505 <ul>
    506   <li>  - .</li>
    507   <li>      UI   .</li>
    508 </ul>
    509 
    510 <p>         
    511 .     .</p>
    512 <ul>
    513   <li>      .</li>
    514   <li>{@link
    515 android.widget.ListView}  {@link android.widget.GridView}      (  
    516      ).</li>
    517 </ul>
    518 
    519 <p>      .</p>
    520 
    521 
    522 <h4 id="CABforViews">      </h4>
    523 
    524 <p>           
    525    .</p>
    526 <ol>
    527   <li>{@link android.view.ActionMode.Callback}  .   
    528     ,      ,    
    529     .</li>
    530   <li>   {@link android.app.Activity#startActionMode startActionMode()} 
    531 (  - ).</li>
    532 </ol>
    533 
    534 <p>:</p>
    535 
    536 <ol>
    537   <li>{@link android.view.ActionMode.Callback ActionMode.Callback}  .
    538 <pre>
    539 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
    540 
    541     // Called when the action mode is created; startActionMode() was called
    542     &#64;Override
    543     public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    544         // Inflate a menu resource providing context menu items
    545         MenuInflater inflater = mode.getMenuInflater();
    546         inflater.inflate(R.menu.context_menu, menu);
    547         return true;
    548     }
    549 
    550     // Called each time the action mode is shown. Always called after onCreateActionMode, but
    551     // may be called multiple times if the mode is invalidated.
    552     &#64;Override
    553     public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    554         return false; // Return false if nothing is done
    555     }
    556 
    557     // Called when the user selects a contextual menu item
    558     &#64;Override
    559     public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    560         switch (item.getItemId()) {
    561             case R.id.menu_share:
    562                 shareCurrentItem();
    563                 mode.finish(); // Action picked, so close the CAB
    564                 return true;
    565             default:
    566                 return false;
    567         }
    568     }
    569 
    570     // Called when the user exits the action mode
    571     &#64;Override
    572     public void onDestroyActionMode(ActionMode mode) {
    573         mActionMode = null;
    574     }
    575 };
    576 </pre>
    577 
    578 <p>  <a href="#options-menu"> </a>      . ,     {@link
    579 android.view.ActionMode}  . {@link
    580 android.view.ActionMode} API 
    581 {@link android.view.ActionMode#setTitle setTitle()} {@link
    582 android.view.ActionMode#setSubtitle setSubtitle()}        CAB  (  
    583     ).</p>
    584 
    585 <p>,       {@code mActionMode}  null
    586   .          
    587   .</p>
    588 </li>
    589 
    590   <li>{@link android.app.Activity#startActionMode startActionMode()} 
    591 {@link
    592 android.view.View} -        .</p>
    593 
    594 <pre>
    595 someView.setOnLongClickListener(new View.OnLongClickListener() {
    596     // Called when the user long-clicks on someView
    597     public boolean onLongClick(View view) {
    598         if (mActionMode != null) {
    599             return false;
    600         }
    601 
    602         // Start the CAB using the ActionMode.Callback defined above
    603         mActionMode = getActivity().startActionMode(mActionModeCallback);
    604         view.setSelected(true);
    605         return true;
    606     }
    607 });
    608 </pre>
    609 
    610 <p>{@link android.app.Activity#startActionMode startActionMode()}  
    611  {@link android.view.ActionMode} .     
    612          .  
    613 {@link android.view.ActionMode}  {@link android.view.ActionMode}    
    614      null   
    615     .</p>
    616 </li>
    617 </ol>
    618 
    619 
    620 
    621 <h4 id="CABforListView">ListView  GridView    </h4>
    622 
    623 <p>{@link android.widget.ListView}  {@link
    624 android.widget.GridView}( {@link android.widget.AbsListView}   )    
    625         .</p>
    626 
    627 <ul>
    628   <li>{@link android.widget.AbsListView.MultiChoiceModeListener}    
    629 {@link android.widget.AbsListView#setMultiChoiceModeListener
    630 setMultiChoiceModeListener()}     .        
    631  ,      ,
    632 {@link android.view.ActionMode.Callback}       .</li>
    633 
    634   <li>{@link
    635 android.widget.AbsListView#CHOICE_MODE_MULTIPLE_MODAL}  {@link android.widget.AbsListView#setChoiceMode setChoiceMode()} .</li>
    636 </ul>
    637 
    638 <p>:</p>
    639 
    640 <pre>
    641 ListView listView = getListView();
    642 listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    643 listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
    644 
    645     &#64;Override
    646     public void onItemCheckedStateChanged(ActionMode mode, int position,
    647                                           long id, boolean checked) {
    648         // Here you can do something when items are selected/de-selected,
    649         // such as update the title in the CAB
    650     }
    651 
    652     &#64;Override
    653     public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    654         // Respond to clicks on the actions in the CAB
    655         switch (item.getItemId()) {
    656             case R.id.menu_delete:
    657                 deleteSelectedItems();
    658                 mode.finish(); // Action picked, so close the CAB
    659                 return true;
    660             default:
    661                 return false;
    662         }
    663     }
    664 
    665     &#64;Override
    666     public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    667         // Inflate the menu for the CAB
    668         MenuInflater inflater = mode.getMenuInflater();
    669         inflater.inflate(R.menu.context, menu);
    670         return true;
    671     }
    672 
    673     &#64;Override
    674     public void onDestroyActionMode(ActionMode mode) {
    675         // Here you can make any necessary updates to the activity when
    676         // the CAB is removed. By default, selected items are deselected/unchecked.
    677     }
    678 
    679     &#64;Override
    680     public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    681         // Here you can perform updates to the CAB due to
    682         // an {@link android.view.ActionMode#invalidate} request
    683         return false;
    684     }
    685 });
    686 </pre>
    687 
    688 <p>.   -    {@link
    689 android.widget.AbsListView.MultiChoiceModeListener#onCreateActionMode onCreateActionMode()}
    690        .     
    691      .</p>
    692 
    693 <p>       , 
    694    UI         . 
    695  -      .    
    696 {@link android.widget.AbsListView#setItemChecked setItemChecked()} 
    697            .</p>
    698 
    699 
    700 
    701 
    702 <h2 id="PopupMenu">  </h2>
    703 
    704 <div class="figure" style="width:220px">
    705 <img src="{@docRoot}images/ui/popupmenu.png" alt="" />
    706 <p><strong> 4.</strong> Gmail        
    707   .</p>
    708 </div>
    709 
    710 <p>{@link android.widget.PopupMenu} {@link android.view.View}   .
    711       ,    .     .</p>
    712 <ul>
    713   <li>  <em></em>      (: 
    714  4 Gmail   ).
    715     <p class="note"><strong>:</strong>    .   
    716    <em> </em> . 
    717     , <a href="#CAB">  </a>  <a href="#FloatingContextMenu">  </a> .</p></li>
    718   <li>    (: ""  , 
    719   ""     ).</li>
    720   <li>    {@link android.widget.Spinner}   .
    721 </li>
    722 </ul>
    723 
    724 
    725 <p class="note"><strong>:</strong> {@link android.widget.PopupMenu} API
    726  11    .</p>
    727 
    728 <p><a href="#xml">XML  </a> ,      .</p>
    729 <ol>
    730   <li>  {@link android.widget.PopupMenu} .  
    731   {@link android.content.Context}  {@link android.view.View} 
    732     .</li>
    733   <li>{@link android.view.MenuInflater} {@link
    734 android.widget.PopupMenu#getMenu() PopupMenu.getMenu()}  {@link
    735 android.view.Menu}    . API  14    
    736 {@link android.widget.PopupMenu#inflate PopupMenu.inflate()}   .</li>
    737   <li>{@link android.widget.PopupMenu#show() PopupMenu.show()} .</li>
    738 </ol>
    739 
    740 <p> ,     {@link android.R.attr#onClick android:onClick}  
    741  .</p>
    742 
    743 <pre>
    744 &lt;ImageButton
    745     android:layout_width="wrap_content" 
    746     android:layout_height="wrap_content" 
    747     android:src="@drawable/ic_overflow_holo_dark"
    748     android:contentDescription="@string/descr_overflow_button"
    749     android:onClick="showPopup" />
    750 </pre>
    751 
    752 <p>       .</p>
    753 
    754 <pre>
    755 public void showPopup(View v) {
    756     PopupMenu popup = new PopupMenu(this, v);
    757     MenuInflater inflater = popup.getMenuInflater();
    758     inflater.inflate(R.menu.actions, popup.getMenu());
    759     popup.show();
    760 }
    761 </pre>
    762 
    763 <p>API  14  , {@link
    764 android.widget.PopupMenu#inflate PopupMenu.inflate()}        .</p>
    765 
    766 <p>         
    767 . {@link
    768 android.widget.PopupMenu.OnDismissListener}       .</p>
    769 
    770 <h3 id="PopupEvents">  </h3>
    771 
    772 <p>      ,{@link android.widget.PopupMenu#setOnMenuItemClickListener
    773 setOnMenuItemclickListener()} 
    774 {@link
    775 android.widget.PopupMenu.OnMenuItemClickListener}   {@link
    776 android.widget.PopupMenu} .      {@link
    777 android.widget.PopupMenu.OnMenuItemClickListener#onMenuItemClick onMenuItemClick()} 
    778 .</p>
    779 
    780 <p>:</p>
    781 
    782 <pre>
    783 public void showMenu(View v) {
    784     PopupMenu popup = new PopupMenu(this, v);
    785 
    786     // This activity implements OnMenuItemClickListener
    787     popup.setOnMenuItemClickListener(this);
    788     popup.inflate(R.menu.actions);
    789     popup.show();
    790 }
    791 
    792 &#64;Override
    793 public boolean onMenuItemClick(MenuItem item) {
    794     switch (item.getItemId()) {
    795         case R.id.archive:
    796             archive(item);
    797             return true;
    798         case R.id.delete:
    799             delete(item);
    800             return true;
    801         default:
    802             return false;
    803     }
    804 }
    805 </pre>
    806 
    807 
    808 <h2 id="groups">  </h2>
    809 
    810 <p>       .     
    811   .</p>
    812 <ul>
    813   <li>{@link android.view.Menu#setGroupVisible(int,boolean)
    814 setGroupVisible()}     </li>
    815   <li>{@link android.view.Menu#setGroupEnabled(int,boolean)
    816 setGroupEnabled()}     </li>
    817   <li>{@link
    818 android.view.Menu#setGroupCheckable(int,boolean,boolean) setGroupCheckable()}      </li>
    819 </ul>
    820 
    821 <p>  {@code &lt;group&gt;}   {@code &lt;item&gt;}  
    822 {@link
    823 android.view.Menu#add(int,int,int,int) add()}   ID     .</p>
    824 
    825 <p>     .</p>
    826 
    827 <pre>
    828 &lt;?xml version="1.0" encoding="utf-8"?&gt;
    829 &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    830     &lt;item android:id="@+id/menu_save"
    831           android:icon="@drawable/menu_save"
    832           android:title="@string/menu_save" /&gt;
    833     &lt;!-- menu group --&gt;
    834     &lt;group android:id="@+id/group_delete"&gt;
    835         &lt;item android:id="@+id/menu_archive"
    836               android:title="@string/menu_archive" /&gt;
    837         &lt;item android:id="@+id/menu_delete"
    838               android:title="@string/menu_delete" /&gt;
    839     &lt;/group&gt;
    840 &lt;/menu&gt;
    841 </pre>
    842 
    843 <p>       .        
    844 .            . 
    845  ID      .   
    846     .  ,    {@code
    847 android:showAsAction="ifRoom"} ,       
    848   .</p>
    849 
    850 
    851 <h3 id="checkable">    </h3>
    852 
    853 <div class="figure" style="width:200px">
    854   <img src="{@docRoot}images/radio_buttons.png" height="333" alt="" />
    855   <p class="img-caption"><strong> 5.</strong>   
    856     .</p>
    857 </div>
    858 
    859 <p>   ,     , 
    860           
    861 .  5         
    862 .</p>
    863 
    864 <p class="note"><strong>:</strong> ( )     
    865      .        , 
    866     /   
    867     .</p>
    868 
    869 <p>{@code &lt;item&gt;}  {@code
    870 android:checkable}          
    871 {@code &lt;group&gt;}  {@code android:checkableBehavior}          . 
    872  ,          .</p>
    873 
    874 <pre>
    875 &lt;?xml version="1.0" encoding="utf-8"?&gt;
    876 &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    877     &lt;group android:checkableBehavior="single"&gt;
    878         &lt;item android:id="@+id/red"
    879               android:title="@string/red" /&gt;
    880         &lt;item android:id="@+id/blue"
    881               android:title="@string/blue" /&gt;
    882     &lt;/group&gt;
    883 &lt;/menu&gt;
    884 </pre>
    885 
    886 <p>{@code android:checkableBehavior}     .
    887 <dl>
    888   <dt>{@code single}</dt>
    889     <dd>     ( ).</dd>
    890   <dt>{@code all}</dt>
    891     <dd>    ().</dd>
    892   <dt>{@code none}</dt>
    893     <dd>    .</dd>
    894 </dl>
    895 
    896 <p>{@code &lt;item&gt;}  {@code android:checked}        
    897 {@link
    898 android.view.MenuItem#setChecked(boolean) setChecked()}       .</p>
    899 
    900 <p>   ,       
    901 (: {@link android.app.Activity#onOptionsItemSelected(MenuItem) onOptionsItemSelected()}).   
    902    .       
    903   . 
    904 {@link android.view.MenuItem#isChecked()}    (     )    
    905 {@link android.view.MenuItem#setChecked(boolean) setChecked()}     . :</p>
    906 
    907 <pre>
    908 &#64;Override
    909 public boolean onOptionsItemSelected(MenuItem item) {
    910     switch (item.getItemId()) {
    911         case R.id.vibrate:
    912         case R.id.dont_vibrate:
    913             if (item.isChecked()) item.setChecked(false);
    914             else item.setChecked(true);
    915             return true;
    916         default:
    917             return super.onOptionsItemSelected(item);
    918     }
    919 }
    920 </pre>
    921 
    922 <p>     ,      (   )
    923  .
    924    ,     
    925         
    926  .</p>
    927 
    928 <p class="note"><strong>:</strong>
    929             
    930  .       ,
    931 <a href="{@docRoot}guide/topics/data/data-storage.html#pref">  </a>    .</p>
    932 
    933 
    934 
    935 <h2 id="intents">    </h2>
    936 
    937 <p>{@link android.content.Intent} 
    938       (           ).     
    939        ,
    940       {@link android.app.Activity#startActivity(Intent) startActivity()} 
    941   (: {@link
    942 android.app.Activity#onOptionsItemSelected(MenuItem) onOptionsItemSelected()} ).</p>
    943 
    944 <p>   
    945       ,     
    946            .
    947     Android          . 
    948  Android        .</p>
    949 
    950 <p>           .</p>
    951 <ol>
    952   <li>
    953  {@link android.content.Intent#CATEGORY_ALTERNATIVE} /
    954 {@link android.content.Intent#CATEGORY_SELECTED_ALTERNATIVE},     .</li>
    955   <li>{@link
    956 android.view.Menu#addIntentOptions(int,int,int,ComponentName,Intent[],Intent,int,MenuItem[])
    957 Menu.addIntentOptions()} .  Android     
    958    .</li>
    959 </ol>
    960 
    961 <p>     , 
    962    .</p>
    963 
    964 <p class="note"><strong>:</strong>
    965 {@link android.content.Intent#CATEGORY_SELECTED_ALTERNATIVE}      
    966  .   {@link
    967 android.app.Activity#onCreateContextMenu(ContextMenu,View,ContextMenuInfo)
    968 onCreateContextMenu()}     .</p>
    969 
    970 <p>:</p>
    971 
    972 <pre>
    973 &#64;Override
    974 public boolean onCreateOptionsMenu(Menu menu){
    975     super.onCreateOptionsMenu(menu);
    976 
    977     // Create an Intent that describes the requirements to fulfill, to be included
    978     // in our menu. The offering app must include a category value of Intent.CATEGORY_ALTERNATIVE.
    979     Intent intent = new Intent(null, dataUri);
    980     intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    981 
    982     // Search and populate the menu with acceptable offering applications.
    983     menu.addIntentOptions(
    984          R.id.intent_group,  // Menu group to which new items will be added
    985          0,      // Unique item ID (none)
    986          0,      // Order for the items (none)
    987          this.getComponentName(),   // The current activity name
    988          null,   // Specific items to place first (none)
    989          intent, // Intent created above that describes our requirements
    990          0,      // Additional flags to control items (none)
    991          null);  // Array of MenuItems that correlate to specific items (none)
    992 
    993     return true;
    994 }</pre>
    995 
    996 <p>         
    997   <code>android:label</code>
    998   ,         . 
    999 {@link android.view.Menu#addIntentOptions(int,int,int,ComponentName,Intent[],Intent,int,MenuItem[])
   1000 addIntentOptions()}      .</p>
   1001 
   1002 <p class="note"><strong>:</strong> {@link
   1003 android.view.Menu#addIntentOptions(int,int,int,ComponentName,Intent[],Intent,int,MenuItem[])
   1004 addIntentOptions()}           
   1005 .</p>
   1006 
   1007 
   1008 <h3 id="AllowingToAdd">    </h3>
   1009 
   1010 <p>       
   1011        (    ).</p>
   1012 
   1013 <p>   ,     
   1014  ,    {@link android.content.Intent#CATEGORY_ALTERNATIVE}
   1015 /{@link android.content.Intent#CATEGORY_SELECTED_ALTERNATIVE} 
   1016   . :</p>
   1017 <pre>
   1018 &lt;intent-filter label="&#64;string/resize_image">
   1019     ...
   1020     &lt;category android:name="android.intent.category.ALTERNATIVE" />
   1021     &lt;category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
   1022     ...
   1023 &lt;/intent-filter>
   1024 </pre>
   1025 
   1026 <p>      
   1027 <a href="/guide/components/intents-filters.html">  </a>  .</p>
   1028 
   1029 <p>     
   1030 <a href="{@docRoot}resources/samples/NotePad/src/com/example/android/notepad/NoteEditor.html">Note
   1031 Pad</a>   .</p>
   1032