Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can place overflow menu below toolbar instead of overflow menu to overlaps the tool bar

intial viewon tapping share icon ,popup covers the toolbar contenton tapping see all option in popup, it shows properly below the toolbar

I have added the shareActionProvider for the tool bar my problem is as soon as i tap on share icon the popup menu will cover the toolbar content but when i tap on see all option listed under the popup menu , the popup menu will perfectly settle below the tool bar.

My requirement is as soon as i tap on share icon my popup menu should be populated below the tool bar not after i select the see all option.

menu.xml

<item
    android:id="@+id/menu_item_share"
    app:showAsAction="always"
    android:title="Share"
    android:icon="@drawable/abc_ic_menu_share_mtrl_alpha"/>

Java code

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem item = menu.findItem(R.id.menu_item_share);

    mShareActionProvider = new ShareActionProvider(getActivity()) {
        @Override
        public View onCreateActionView() {
            return null;
        }
    };

    MenuItemCompat.setActionProvider(item, mShareActionProvider);

    if (mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(createShareIntent());
    }
}

style.xml

<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
    <item name="actionOverflowMenuStyle">@style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
    <item name="android:popupBackground">@color/colorPrimary</item>

    <!-- Required for pre-Lollipop. -->
    <item name="overlapAnchor">false</item>
    <item name="android:dropDownVerticalOffset">-4.0dip</item>

    <!-- Required for Lollipop. -->
    <item name="android:overlapAnchor">false</item>
    <item name="android:dropDownVerticalOffset">-4.0dip</item>
</style>
like image 784
Vijayalaxmi Avatar asked Dec 15 '15 07:12

Vijayalaxmi


1 Answers

According to the Material Design specifications (see the Menus section):

A menu is a temporary sheet of paper that always overlaps the app bar, rather than behaving as an extension of the app bar.

Menu overlap app bar

So what you are seeing is the correct Material design for menus.


To change it in your main style use <item name="actionOverflowMenuStyle">@style/OverflowMenu</item>, where

<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
  <!-- Required for pre-Lollipop. -->
   <item name="overlapAnchor">false</item>
   <item name="android:dropDownVerticalOffset">-4.0dip</item>
  <!-- Required for Lollipop. -->
   <item name="android:overlapAnchor">false</item>
   <item name="android:dropDownVerticalOffset">4.0dip</item>
</style>

For Lollipop style must be in values-v21.

like image 89
piotrek1543 Avatar answered Oct 03 '22 16:10

piotrek1543