设置Android PopupMenu分界线的样式 [英] Styling Android PopupMenu Divider Lines

查看:903
本文介绍了设置Android PopupMenu分界线的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用了两个PopupMenu,它们均按预期工作

I'm using a couple of PopupMenus in my app and they all working as expected

但是我想用白线将各个项目分开,但是我找不到要在何处设置此项目.我希望可以访问底层的ListView,但这似乎是不可能的.我也看不到与分隔线相关的样式项.

But I would like to have white lines separating the individual items, but I can't find where I'm meant to be setting this. I was hoping I could get to the underlying ListView but that doesn't seem to be possible. I can't see an style item that relates to the divider line either.

这可能吗,应该在哪里/如何设置?

Is this possible, where/how should I be setting this?

推荐答案

我已经能够使用以下技术更新PopupMenu上的分隔线颜色(基于此答案的线索https://stackoverflow.com/a/40017199/285190 )

I've been able to update the divider colour on a PopupMenu using the following technique (based on clues from this answer https://stackoverflow.com/a/40017199/285190)

创建如下样式...

<style name="popupMenuStyle" >
    <item name="android:textColor">#ffffff</item>
    <item name="android:itemBackground">#000000</item>
    <item name="android:divider">#eaeaea</item>
    <item name="android:dividerHeight">1dp</item>
</style>

然后在创建菜单时创建一个上下文包装器

Then when you create the menu create a context wrapper

Context wrapper = new ContextThemeWrapper(mContext, R.style.popupMenuStyle);
PopupMenu popup = new PopupMenu(wrapper, sourceView);

这确实显示了一条分隔线,但是菜单的高度似乎并未正确计算以包含新的分隔线,并显示了垂直滚动条.

This does show a dividing line, BUT the height of the menu doesn't appear to be calculated correctly to include the new divider and a vertical scrollbar is displayed.

如果有人知道原因,请添加评论

If anyone knows the reason please add a comment

这篇关于设置Android PopupMenu分界线的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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