I have group inside menu.xml
and I try to change the visibility of the group.
//in the onCreate
myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.setGroupVisible(R.id.group, showGroup);
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
This doesn't change the visibility of the group when I open the app.(when I call to invalidateOptionsMenu
).(it change the visibility only of the items inside the three dot menu.. not the drawables icons).
Only if I click the menu three dot it starts to work as I want.
If I open the app and show dialog and close it the menu works ok..
How can I fix it to work when I open the app?
Thanks
Edit
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group
android:id="@+id/group"
>
<item
android:id="@+id/delete_btn"
android:icon="@drawable/ic_delete_black_24dp"
android:title="delete"
app:showAsAction="always"
/>
<item
android:id="@+id/invite_btn"
android:icon="@drawable/ic_group_add_black_24dp"
android:title="invite"
app:showAsAction="never"
/>
</group>
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="Sign Out"
app:showAsAction="never"/>
</menu>
if I run this code:
this.showGroup=true;
invalidateOptionsMenu();
it shows only the invite_btn inside the 3-dots.
when I click the 3-dots it render the icon of the delete_btn.
In this time if I run this code
this.showGroup=false;
invalidateOptionsMenu();
.....
this.showGroup=true;
invalidateOptionsMenu();
.....
every thing works well.