I have a menu with two items (in one fragment is the edit icon and in the other ones is the new icon(that is working fine)), and an overflow menu with three items inside, my issue is I have an empty space in the top of my overflow menu. My activity has a ViewPager with three fragments. I have tried removing android:scaleType, adding orderInCategory and still the issue.
<item
android:id="@+id/btn_refresh"
android:icon="@drawable/ic_action_refresh"
android:title="@string/action_refresh"
android:scaleType="fitXY"
app:showAsAction="always"/>
<item
android:id="@+id/btn_new"
android:icon="@drawable/ic_action_add"
android:title="@string/action_new"
android:orderInCategory="2"
app:showAsAction="always"/>
<item android:id="@+id/btn_edit"
android:icon="@drawable/ic_action_edit"
android:title="@string/action_edit"
android:orderInCategory="2"
app:showAsAction="always"/>
<item android:id="@+id/recalculate_values"
android:title="@string/recalculate_values"
android:scaleType="fitXY"
app:showAsAction="never"/>
<item android:id="@+id/about"
android:title="@string/about"
android:scaleType="fitXY"
app:showAsAction="never"/>
<item android:id="@+id/exit"
android:title="@string/exit"
android:scaleType="fitXY"
app:showAsAction="never"/>
I have tried some answer I found in these post Android - Correct use of invalidateOptionsMenu() and Action Bar shows up empty in Android app , so I call invalidateOptionsMenu() after this code:
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.mipmap.ic_launcher);
On my activity:
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem mNew = menu.findItem(R.id.btn_new);
MenuItem mEdit = menu.findItem(R.id.btn_edit);
int frag = viewPager.getCurrentItem();
if(frag == 0) {
mNew.setVisible(false);
mEdit.setVisible(true);
return true;
}else {
mNew.setVisible(true);
mEdit.setVisible(false);
}
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_show_event, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
//manage items
}
And in each fragment, I call in the method onCreateView() setHasOptionsMenu(true); I would appreciate any tips, thanks in advance.
EDIT I attach the xml activity if helps
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/AppTheme"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />