0

I have the following menu that i declare in Main activity :

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);

 //... populate with menu.add()

}

The menu icon looks like 3 dotts and it's position is on the action bar on the right side. In my app i use Fragments and i want to change the menu icon ( the icon i press to open de menu items ) depending on the fragment it's in front.

How can i do that programmatically?

Also on some of my fragments i don't want the menu to appear. For this i use inside those fragments :

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
    super.onCreateOptionsMenu(menu, inflater);
    menu.clear();
}

And i try to find a way using the menu var to change the icon of the menu. But i did not find a way.

So.... can you please show me how to change the menu icon programmatically?

Thanks,

  • did you mean the Navigation Drawer ? – Mohamed ALOUANE Oct 30 '14 at 16:46
  • noup. that one i change it through : new ActionBarDrawerToggle. –  Oct 30 '14 at 16:52
  • In a defalut app : you press the menu icon ( those 3 dotts that i want to change whit other icon ) and it shows you 1 item call "settings" –  Oct 30 '14 at 16:54
  • Do you have this in your code , ?? ` mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open,R.string.drawer_close) ` – Mohamed ALOUANE Oct 30 '14 at 17:02

2 Answers2

0

Look to this question:

How to change the Option menu icon in the Action Bar?

Try this:

<style name="YourTheme" parent="@android:style/Theme.Holo.Light">
     <item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
</style>

<style name="Widget.ActionButton.Overflow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
     <item name="android:src">@android:drawable/ic_menu_moreoverflow_holo_dark</item>
     <item name="android:background">?android:attr/actionBarItemBackground</item>
     <item name="android:contentDescription">@string/action_menu_overflow_description</item>
</style>

Update:

To change it programatically see this question: Changing the Android Overflow menu icon programmatically

Hope this will help you.

Community
  • 1
  • 1
Volodymyr Yatsykiv
  • 3,181
  • 1
  • 24
  • 28
0

If i understand correctly, what you mean is the overflow icon. This is how i do it :

<!--inside your styles.xml-->
<style name="AppBaseTheme" parent="@android:style/Theme.Holo">
<item name="android:actionOverflowButtonStyle">@style/overflow</item>
</style>

<style name="overflow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
    <item name="android:src">@drawable/custom_overflow</item>
</style>

UPDATE :

To change it programatically : Changing the Android Overflow menu icon programmatically

Community
  • 1
  • 1
Blaze Tama
  • 10,828
  • 13
  • 69
  • 129