【发布时间】:2017-10-05 20:17:40
【问题描述】:
我有一个带有溢出菜单的操作栏。 在那个溢出菜单中,我在每个项目中都有文本。 目前这些项目左对齐。 我希望它们通过 XML 对齐到溢出菜单的中心。
下面是我的 theme.xml - 在“myCustomMenuTextApearance”样式中,我使用了“gravity”属性,但它不起作用。 当我将“重力”属性移动到“MyAppActionBarTheme”样式时,它工作的项目是居中的,而且我在我的 Activity 布局中拥有的所有 TextView 的其余部分也是如此。 这根本不是我想要的。
我找到了这些链接,但没有找到任何帮助: 1.https://stackoverflow.com/questions/22702588/align-items-inside-of-a-menu-coming-from-actionbar
How to align menu item text in Actionbar overflow menu
Align Center Menu Item text in android
<?xml version="1.0" encoding="utf-8"?>
<style name="MyAppActionBarTheme" parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle" tools:targetApi="11">@style/MyApp.PopupMenu</item>
<item name="android:itemTextAppearance">@style/myCustomMenuTextApearance</item>
<item name="android:actionBarStyle" tools:targetApi="11">@style/MyApp.ActionBar</item>
</style>
<!-- The beef: background color for Action Bar overflow menu -->
<style name="MyApp.PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">@drawable/ab_menu_bkg</item>
</style>
<style name="myCustomMenuTextApearance" parent="@android:style/TextAppearance.Widget.TextView.PopupMenu">
<item name="android:textColor">@color/red</item>
<item name="android:gravity">center_horizontal</item>
</style>
<!-- Bonus: if you want to style whole Action Bar, not just the menu -->
<style name="MyApp.ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid">
<!-- Blue background color & black bottom border -->
<item name="android:background">@color/red</item>
</style>
任何帮助将不胜感激。
【问题讨论】:
-
你试过在 myCustomMenuTextApearance 上设置
- -1dp
吗? -
是的,但没有帮助。
-
您找到解决方案了吗?
标签: android android-actionbar overflow-menu