Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ContextMenu position is messed up in Android 7

I have an app with a simple listview and context menu in it. pre android 7, everything looks ok:

when clicking an item at the bottom of the list: enter image description here

when clicking an item at the top of the list: enter image description here

But wit android 7...

when clicking an item at the bottom of the list: enter image description here

when clicking an item at the top of the list: enter image description here

Was there any change in the position of the context menu?

like image 551
amitfr Avatar asked Nov 29 '16 13:11

amitfr


2 Answers

If anyone still has the same problem, just add this to your theme folder (v14)

<item name="android:overlapAnchor">true</item>
like image 95
Assan Murad Avatar answered Nov 02 '22 17:11

Assan Murad


I found a solution for this somewhere (can't remember where). The problem is between the new context menu and the Holo themes.

Solution Details:

I added a style in values-v24 folder that looks like:

<resources>

<style name="ContextPopupMenuStyleLight" parent="@android:style/Widget.Holo.Light.PopupMenu">
    <item name="android:overlapAnchor">true</item>
</style>

<style name="ContextPopupMenuStyleDark" parent="@android:style/Widget.Holo.PopupMenu">
    <item name="android:overlapAnchor">true</item>
</style>

<style name="AppTheme" parent="AppTheme.Common" >
    <item name="android:contextPopupMenuStyle">@style/ContextPopupMenuStyleLight</item>
</style>

Then, in my default styles.xml I used a style called

AppTheme.Common

That defines all my app style, and an empty style called

<style name="AppTheme" parent="AppTheme.Common" />

and I used that empty style as the default app style. This way, on version > 24, the app uses this extra item regarding context menu overlap anchor to fix the issue (bringing context menu to what they looked like before API 24)

like image 26
amitfr Avatar answered Nov 02 '22 18:11

amitfr