Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From <a href="https://developer.android.com/training/basics/actionbar/adding-buttons.html" rel="nofollow">https://developer.android.com/training/basics/actionbar/adding-buttons.html</a>:</p> <p><strong>Specify the Actions in XML</strong></p> <p>All action buttons and other items available in the action overflow are defined in an XML menu resource. To add actions to the action bar, create a new XML file in your project's res/menu/ directory.</p> <p>Add an element for each item you want to include in the action bar. For example:</p> <pre><code>res/menu/main_activity_actions.xml &lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;!-- Search, should appear as action button --&gt; &lt;item android:id="@+id/action_search" android:icon="@drawable/ic_action_search" android:title="@string/action_search" android:showAsAction="ifRoom" /&gt; &lt;!-- Settings, should always be in the overflow --&gt; &lt;item android:id="@+id/action_settings" android:title="@string/action_settings" android:showAsAction="never" /&gt; &lt;/menu&gt; </code></pre> <p><strong>Add the Actions to the ActionBar</strong></p> <pre><code>@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_activity_actions, menu); return super.onCreateOptionsMenu(menu); } </code></pre> <p><strong>Respond to Action Buttons</strong></p> <pre><code>@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_search: openSearch(); return true; case R.id.action_settings: openSettings(); return true; default: return super.onOptionsItemSelected(item); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload