Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something like this (taken from one of my apps). <strong>The activity in this case extends <code>SherlockFragmentActivity</code>.</strong></p> <pre><code> @Override public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { menu.add(Menu.NONE, R.id.ID_ACTION_EXIT, Menu.NONE,R.string.action_label_exit) .setIcon(android.R.drawable.ic_menu_close_clear_cancel) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected( com.actionbarsherlock.view.MenuItem item) { switch(item.getItemId()){ case R.id.ID_ACTION_EXIT: Main.this.finish(); return true; default: return false; } } </code></pre> <p>The <code>R.id.ACTION_EXIT</code> is placed in <code>res/values/ids.xml</code></p> <pre><code>&lt;resources&gt;&lt;item name="ID_ACTION_EXIT" type="id"/&gt;&lt;/resources&gt; </code></pre> <p>[EDIT] Try this then (extends SherlockListActivity). You have to do some editing first. This code comes from the Sherlock demos. You should download them.</p> <pre><code> @Override public boolean onCreateOptionsMenu(Menu menu) { SubMenu sub = menu.addSubMenu("Theme"); sub.add(0, R.style.Theme_Sherlock, 0, "Default"); sub.add(0, R.style.Theme_Sherlock_Light, 0, "Light"); sub.add(0, R.style.Theme_Sherlock_Light_DarkActionBar, 0, "Light (Dark Action Bar)"); sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home || item.getItemId() == 0) { return false; } THEME = item.getItemId(); Toast.makeText(this, "Theme changed to \"" + item.getTitle() + "\"", Toast.LENGTH_SHORT).show(); return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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