前天在开发过程中遇到一个缺陷问题是,popMenu的item没有分割线,上网看了下上面说只要设置了group在给它设置不同的id就可以了,试了下不行还是不显示,试了下加样式,还是不行分割线不显示。后来找到了个办法在创建时使用contextThemeWrapper就可以了
ContextThemeWrapper contextThemeWrapper =
new ContextThemeWrapper(context, R.style.CustomPopMenuStyle);
PopupMenu popup = new PopupMenu(contextThemeWrapper, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.chat_delete_menu, popup.getMenu());
以下是样式
<!--popMenu的Style-->
<style name="CustomPopMenuStyle" >
<item name="android:itemBackground">@color/color_2C2C2C</item>
<item name="android:dropDownListViewStyle">@style/popmenuDivier</item>
<item name="android:textAppearanceSmallPopupMenu">@style/popmeuText</item>
<item name="android:textAppearanceLargePopupMenu">@style/popmeuText</item>
</style>
<!-- popMenu的背景色-->
<style name="popmenuStyle" >
</style>
<!--popmenu的字体颜色-->
<style name="popmeuText">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">14sp</item>
<item name="android:gravity">center</item>
</style>
<!--popMenu分割线的颜色-->
<style name="popmenuDivier">
<item name="android:divider">@color/color_4C4E55</item>
<item name="android:dividerHeight">1px</item>
</style>
问题不难,其实如果实在实现不了可以换种方式比如popupwindow加listview。