在AppCompat ActionBar弹出菜单中添加边距

4
我正在使用appcompat actionbar。我想在打开的溢出菜单的顶部右侧添加顶部边距。因此,增加其上方的间距,如下图所示。现在下拉菜单在3个点的上方打开。我该如何将其向下推?
谢谢。

enter image description here

2个回答

0

你可以使用工具栏代替操作栏

<android.support.v7.widget.Toolbar 
     android:id="@id/toolbar"
     android:background="@color/color_notification_toolbar"
     android:layout_width="fill_parent"
     android:layout_height="@dimen/abc_action_bar_default_height_material">

    <TextView
          android:textSize="@dimen/abc_text_size_title_material_toolbar"
          android:textStyle="bold"
          android:textColor="@color/color_notification_title"
          android:layout_gravity="center"
          android:id="@id/tvTimeLineTitle" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:text="@string/title" />
  
  /* add your menu items here as simple text views and 
    and give as much margins and paddings as you want  */
  
</android.support.v7.widget.Toolbar>


0

如果您正在引用Activity的默认OptionItem菜单,我猜您无法以编程方式执行此操作,因为API仅允许您填充它,从而添加/删除元素。不过间距应该没问题,因为菜单在各种布局中都是标准化的。

您遇到的间距问题是什么?您能添加一个所需结果的屏幕截图吗?

一个可能不太糟糕的解决方案是使用自定义样式:

<style name="AppTheme" parent="AppBaseTheme">
  <item name="android:actionButtonStyle">@style/MyStyle</item>
</style>

<style name="MyStyle" parent="AppBaseTheme">
   <item name="android:minWidth">XXdip</item>
   <item name="android:padding">XXdip</item>
</style>

这不是我想要的。请查看我的问题更新。@Shine - lyc001

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