Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want to put an icon instead of a button on the ActionBar I recommend you check and download the ActionBarSherlock library to avoid compatibility problems and to make your work easy. For instance, if you have download and installed SherlockActionBar, you should follow nexts steps:</p> <ol> <li><p>Extend your activity from SherlockActivity instead of Activity:</p> <p><pre><code> public class DrawingActivity extends SherlockActivity {...your code} </pre></code></p></li> </ol> <p>Replace the "ic_action_trash" by your icon on res/drawable directories (drawable-hdpi, drawable-ldpi, ...)</p> <ol start="2"> <li>create a xml file on res/menu folder, called menu_main.xml (for example)</li> </ol> <p><img src="https://i.stack.imgur.com/zsHdq.png" alt="enter image description here"></p> <ol start="3"> <li><p>Override the methods onCreateOptionsMenu and onOptionsItemSelected below your OnCreate method in the DrawingActivity class like this:</p> <p><pre><code> @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_main, menu); }</p> <pre><code>@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.delete_events) deleteEvent(); return true; } </code></pre> <p></pre></p></li> </ol> <p>And here is the result:</p> <p><img src="https://i.stack.imgur.com/WC46C.png" alt="enter image description here"></p> <p>However, to check your requirements, I think you should change the methods above like this:</p> <pre>@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //inflater.inflate(R.menu.menu_main, menu); SubMenu submenu = menu.addSubMenu(""); submenu.setIcon( R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark); submenu.add(1, 1, 1, R.string.add); submenu.add(1, 2, 2, R.string.delete); submenu.add(1, 3, 3, R.string.about); submenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); } public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case 1: addEvent(); break; case 2: deleteEvent(); break; case 3: about(); break; default: return true; } return true; } </code></pre> <p>When you click on the top icon you would see this: <img src="https://i.stack.imgur.com/SigsT.png" alt="enter image description here"> </p> <p>Hope this works for you!</p>
 

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