Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Exactly last night I was struggling with this but eventually managed to solve it, so here is my solution: These are the relevant parts from MainActivity: </p> <pre><code>import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; public class MainActivity extends SherlockFragmentActivity { . . . @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getSupportMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item){ return super.onOptionsItemSelected(item); } } </code></pre> <p>Here is my menu main.xml: </p> <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:id="@+id/action_settings" android:orderInCategory="100" android:showAsAction="never" android:title="@string/action_settings"/&gt; &lt;/menu&gt; </code></pre> <p>and here is my Fragment: </p> <pre><code>import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; public class TestFrag extends SherlockFragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); . . setHasOptionsMenu(true); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.add(Menu.NONE, android.R.id.home, 100, "Home"); } @Override public boolean onOptionsItemSelected(MenuItem item){ switch(item.getItemId()) { case android.R.id.home: // Do whatever you want when Home is clicked. Toast.makeText(getSherlockActivity(), "Home is clicked", Toast.LENGTH_SHORT).show(); return true; default: return super.onOptionsItemSelected(item); } } } </code></pre> <p>This is what I am getting: <img src="https://i.stack.imgur.com/awKzk.jpg" alt="Menu items from both the parent activity and the fragment."></p> <p>I hope this helps in any way.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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