我想更改选项菜单的默认分隔颜色,那么可以给我一些建议或技术吗?
答案 0 :(得分:0)
您可以通过将主题设置为弹出菜单
来实现在res文件夹
中的style.xml文件中使用以下代码 <style name="MyThemePopup" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">@color/white</item>
<item name="android:dividerHeight">2px</item>
<item name="android:divider">#F00</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@color/opaque_black_color_dark</item>
</style>
上面的代码用于创建主题,其中<item name="android:divider">#F00</item>
用于将颜色设置为分隔符
之后,您可以通过清单文件
将创建的主题设置为弹出菜单所在的活动 <activity
android:name="com.android.MainActivity"
android:theme="@style/MyThemePopup" />
希望这段代码可以帮助您实现快乐编码的要求:)
答案 1 :(得分:0)
对我来说什么都没有,也许是因为appCompat版本?
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="android:dividerHeight">2dp</item>
<item name="android:divider">@color/ucc_blue</item>
</style>
如果我将它放在MyActionBar样式或AppTheme样式中都无效。但设置分隔符高度确实使我的OptionMenu可滚动....
也许它不起作用,因为它们是subMenuItems?
答案 2 :(得分:0)
将此项添加到应用主题:
<style name="theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>
</style>
<style name="MyDropDownListView" parent="@android:style/Widget.ListView.DropDown">
<item name="android:divider">@color/transparent</item>
</style>
答案 3 :(得分:0)
Its working for me in Navigationmenu.
This below line is mandatory.
<item name="android:listDivider">@color/white</item>
//This is ur style
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:listDivider">@color/white</item>
</style>
//This is ur menu item.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_profile"
android:icon="@drawable/m_profile"
android:title="@string/my_profile" />
<group android:id="@+id/my_id">
<item
android:id="@+id/nav_coming"
android:icon="@drawable/m_coming"
android:title="@string/comingsoon" />
</group>
</group>
</menu>
答案 4 :(得分:0)
对于那些尚未找到问题答案的人来说,这就是它对我有用的方式,并希望它对你也有用:
<style name="PopupMenu">
<item name="android:itemBackground">@color/background_medium_gray</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:textColor">@android:color/black</item>
<item name="android:colorBackground">@color/BackgroundGray</item>
<item name="android:dividerHeight">1dp</item>
</style>
Context context = new ContextThemeWrapper(getActivity(), R.style.PopupMenu);
final PopupMenu popupMenu = new PopupMenu(context, view);
final MenuInflater menuInflater = popupMenu.getMenuInflater();