减小菜单项宽度、高度和文本视图大小

16

我做了一个菜单溢出项目。我需要减小菜单项的宽度、高度和文本视图大小。

我参考了这篇文章,但它对我不起作用。我已经发布了与此相关的代码和截图:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    >

    <item
        android:id="@+id/add"
        android:icon="@drawable/down"
        android:title="Read"
        android:showAsAction="never"
        />
    <item
        android:id="@+id/add2"
        android:icon="@drawable/down"
        android:title="write"
        android:showAsAction="never"
        />

    <item
        android:id="@+id/add3"
        android:icon="@drawable/down"
        android:title="bold"
        android:showAsAction="never"
        />
</menu>

菜单项截图:

在此输入图片描述

styles.xml:

   <style name="AppBaseTheme" parent="android:Theme.Light">

    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
    </style>

    <style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.ActionButton.Overflow">
        <item name="android:src">@drawable/down</item>

    </style>

我唯一的问题是,我需要在菜单项中减小宽度、高度和文本视图大小。

4个回答

16

我可以通过以下代码帮助减小菜单项的高度和文本大小:

res/values/styles.xml:

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
 
        <item name="android:dropDownListViewStyle">@style/PopupMenuListView</item>
        <item name="android:actionBarWidgetTheme">@style/PopupMenuTextView</item>
        <item name="android:popupMenuStyle">@style/PopupMenu</item>
 
        <!-- Change Overflow Menu ListView Item Height & Property -->
        <item name="android:listPreferredItemHeightSmall">10dp</item>
        <item name="android:listPreferredItemPaddingLeft">5dp</item>
        <item name="android:listPreferredItemPaddingRight">5dp</item>
    </style>
 
    <!-- Change Overflow Menu ListView Divider Property -->
    <style name="PopupMenuListView" parent="@android:style/Widget.Holo.ListView.DropDown">
        <item name="android:divider">#FF0000</item>
        <item name="android:dividerHeight">2dp</item>
    </style>
 
    <!-- Change Overflow Menu ListView Text Size and Text Size -->
     <style name="PopupMenuTextView" parent="@style/android:Theme.Holo.Light">
        <item name="android:textColor">#00FF00</item>
        <item name="android:textSize">5sp</item>
    </style>
 
     <!-- Change Overflow Menu Background -->
     <style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
        <item name="android:popupBackground">#888888</item>
    </style>
 
</resources>

将上述代码添加到styles.xml(v11)和styles.xml(v14)中。

更多详情:

请参考Action Bar Overflow Menu Customization


4
您能否改变整个窗口的宽度? - Kim Montano
有了上面的代码,@NguyenMinhBinh帮助我减少了文本大小,然后宽度也会相应减小。 - Stephen
如何更改宽度? - Pinkesh Darji
没有更改弹出菜单宽度的选项。 - Vivek

9
使用这个:
<item name="android:listPreferredItemHeightSmall">72dp</item>

例子:

 <style name="popupMenuStyle" parent="@android:style/Widget.PopupMenu">
        <item name="android:popupBackground">@drawable/dropdown_bg</item>
       <item name="android:itemPadding">25dp</item>
       <item name="android:listPreferredItemHeightSmall">70dp</item>


    </style>

2
谢谢@Heena..我为此浪费了一整天的时间。 - Zafar Imam

3
在 style.xml 中添加以下内容:
<item name="android:listPreferredItemHeightSmall">35dp</item>
        <item name="android:listPreferredItemPaddingLeft">5dp</item>
        <item name="android:listPreferredItemPaddingRight">5dp</item>

0
我认为最好的选择是使用菜单项操作布局。
app:actionLayout="@layout/my_custom_layout"
然后进行渗透。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接