How to force PopupMenu to overlap anchor?

How to force PopupMenu to overlap anchor? I would like to recreate something similar to this:

Menus usage

  • How can I change the OverScroll color in Android 2.3.1?
  • what ?android:attr/listPreferredItemHeight is doing and how?
  • Make Toolbar transparent
  • android mapview marker size
  • What's tools:layout in fragment xml file?
  • How can I get contact name with his/her number
  • Related posts:

    How to pass a parcelable object that contains a list of objects?
    How do I use the Android Accelerometer?
    Run-time permission of Marshmallow
    How to get the Correct orientation of the image selected from the Default Image gallery
    Changing the Screen Brightness System Setting Android
    Loading JSON from String into JSONArray on Android
  • Android Activity which overridden functions must call super.*
  • Android - Intercept and pass on all touch events
  • Any simple examples using roboguice with fragments in android?
  • Add custom css to html code with jsoup
  • MATCH_PARENT if sibling view is larger, WRAP_CONTENT if sibling view is smaller
  • android edittext onchange listener
  • 5 Solutions collect form web for “How to force PopupMenu to overlap anchor?”

    Setting overlapAnchor allowed me to overlap anchor view without setting offset:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="popupMenuStyle">@style/PopupMenu</item>
    </style>
    
    <style name="PopupMenu" parent="@style/Widget.AppCompat.Light.PopupMenu">
        <item name="overlapAnchor">true</item>
    </style>
    

    The PopupMenu wraps a ListPopupWindow inside it. This ListPopupWindow wraps AppCompatPopupWindow using this overlapAnchor attribute. All this in the support library.

    Alternative to Paritosh Tonk’s answer:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="popupMenuStyle">@style/Widget.AppCompat.Light.PopupMenu.Overflow</item>
    </style>
    

    or for dark theme:

    <style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
        <item name="popupMenuStyle">@style/Widget.AppCompat.PopupMenu.Overflow</item>
    </style>
    

    Setting android:dropDownVerticalOffset allowed me to overlap anchor view:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="popupMenuStyle">@style/PopupMenu</item>
    </style>
    
    <style name="PopupMenu" parent="@style/Widget.AppCompat.Light.PopupMenu">
        <item name="android:dropDownVerticalOffset">-36dip</item>
    </style>
    

    Have you looked at using PopupWindow instead? Those offer a bit more flexibility in their placement. You can specify the anchor view and an x and y offset which would let you define the overlap.

    I came here when trying to figure out how to create a popup menu that overlaps its anchor when the anchor is in the actionBar. Since this is a prominent search result for that problem, I want to leave the answer here even though I’m not sure whether the solution would work for OP.

    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto" >
        <!-- This item will expand into a submenu -->
        <item
            android:id="@+id/anchor"
            android:icon="@drawable/ic_anchor"
            android:title="@string/anchor"
            app:showAsAction="always">
            <menu>
                <item
                    android:id="@+id/subMenuItemOne"
                    android:showAsAction="never"
                    android:title="SubMenuItemOne"/>
                <item
                    android:id="@+id/subMenuItemTwo"
                    android:showAsAction="never"
                    android:title="SubMenuItemTwo"/>
            </menu>
        </item>
    </menu>
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.