Issue

ListView context menu pop-up doesn't work properly in Android 7.0 and 7.1 Nougat (API 24 and API 25).

Instead of the full menu appearing in the middle of the screen, it now appears collapsed to a single item and either at the very top or at the very bottom of the screen.

Here is the expected behaviour:

Here is how the context menu looks in Android 7.1.1:

The app uses com.android.support:appcompat-v7 library and Theme.Holo.Light theme.

 

 

Resolution

To resolve the issue I had to modify app theme by enabling overlapAnchor in contextPopupMenuStyle. Since contextPopupMenuStyle requires API 24 this cannot be done direly in your main res/values/styles.xml file. Instead, create res/values-v24/styles.xml file which will only apply to API 24 and higher.

Inside the file add the following code:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:contextPopupMenuStyle">@style/myContextPopupMenuStyle</item>
<!-- your other styles used in AppTheme -->
</style>
<style name="myContextPopupMenuStyle" parent="@android:style/Widget.Holo.Light.PopupMenu">
<item name="android:overlapAnchor">true</item>
</style>
</resources>

You will have to modify the above code to replicate your other styles used in the main AppTheme. Or use inheritance so you don't have to duplicate the code.

Result:

Android Studio 2.2.3
February 2017

 

No comments

Leave your comment

In reply to Some User
Captcha Image