2

The menu of my application appears as follows enter image description hereand I need the menu items to appear just where in the limit of the action bar as it appears in the following imageenter image description here Any idea how to do it.

Mickey Mouse
  • 107
  • 1
  • 11

2 Answers2

0

Two way to achieve that one use the custom style at v21

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

or use the android theme

android:theme="@android:style/Theme.Holo.Light"

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

Community
  • 1
  • 1
Shubhank Gupta
  • 833
  • 2
  • 15
  • 35
0
  1. In your values/styles.xml add OverflowMenu style as:

    <style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
        <item name="overlapAnchor">false</item>
        <item name="android:dropDownVerticalOffset">-4dp</item>
    </style>
    
  2. In your values-21/styles.xml add OverflowMenu style as:

    <style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
        <item name="android:overlapAnchor">false</item>
        <item name="android:dropDownVerticalOffset">4dp</item>
    </style>
    
  3. Finally, in your values/styles.xml main style use OverflowMenu style as actionOverflowMenuStyle.

values/styles.xml

    <resources>
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- Customize your theme here. -->

            <item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
        </style>

        <style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
            <item name="overlapAnchor">false</item>
            <item name="android:dropDownVerticalOffset">4.0dp</item>

        </style>

    </resources>
Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61