ContextMenu在Android 7中的位置混乱 [英] ContextMenu position is messed up in Android 7

查看:96
本文介绍了ContextMenu在Android 7中的位置混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有简单列表视图和上下文菜单的应用程序。 android 7之前的
,一切看起来都不错:



当单击列表底部的项目时:



当单击列表顶部的项目时:



但是机智的android 7 ...



当单击列表底部的项目时:



单击列表顶部的项目:



是否有任何变化

解决方案

我在某个地方找到了解决方案(不记得在哪里)。
问题出在新的上下文菜单和Holo主题之间。



解决方案详细信息:



我在values-v24文件夹中添加了以下样式:

 < 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>



然后,以我的默认样式.xml我使用了一种名为

  AppTheme.Common 


这定义了我所有的应用样式,以及一个名为

 <的空样式; style name = AppTheme parent = AppTheme.Common /> 

,我将空样式用作默认应用样式。
这样,在版本> 24的应用程序中,应用程序会使用有关上下文菜单重叠锚的额外项来解决此问题(将上下文菜单带到API 24之前的样子)


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:

when clicking an item at the top of the list:

But wit android 7...

when clicking an item at the bottom of the list:

when clicking an item at the top of the list:

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

解决方案

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)

这篇关于ContextMenu在Android 7中的位置混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆