如何在垂直位置降低菜单

时间:2017-03-27 16:00:56

标签: android material-design

我的应用程序的菜单显示如下enter image description here,我需要菜单项显示在操作栏限制的位置,如下图所示enter image description here任何想法怎么做它

2 个答案:

答案 0 :(得分:0)

实现该方法的两种方法是在v21使用自定义样式

<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
  <!-- Required for pre-Lollipop. -->
   <item name="overlapAnchor">false</item>
   <item name="android:dropDownVerticalOffset">-4.0dp</item>
  <!-- Required for Lollipop. -->
   <item name="android:overlapAnchor">false</item>
   <item name="android:dropDownVerticalOffset">4.0dp</item>
</style>

或使用android主题

android:theme="@android:style/Theme.Holo.Light"

参考How I can place overflow menu below toolbar instead of overflow menu to overlaps the app bar

答案 1 :(得分:0)

  1. values/styles.xml添加OverflowMenu样式中:

    <style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
        <item name="overlapAnchor">false</item>
        <item name="android:dropDownVerticalOffset">-4dp</item>
    </style>
    
  2. values-21/styles.xml添加OverflowMenu样式中:

    <style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
        <item name="android:overlapAnchor">false</item>
        <item name="android:dropDownVerticalOffset">4dp</item>
    </style>
    
  3. 最后,在values/styles.xml主要样式中使用OverflowMenu样式为actionOverflowMenuStyle
  4. <强>值/ styles.xml

        <resources>
            <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
                <!-- Customize your theme here. -->
    
                <item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
            </style>
    
            <style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
                <item name="overlapAnchor">false</item>
                <item name="android:dropDownVerticalOffset">4.0dp</item>
    
            </style>
    
        </resources>