1

我用来ActionMenuView渲染菜单。ActionMenuView但是重叠最后一个动作图标的溢出按钮:

在此处输入图像描述

这是我的代码:

<RelativeLayout
    android:id="@+id/main_topBar"
    android:layout_width="match_parent"
    android:layout_height="90dp"
    android:background="@drawable/header_pattern_back"
    android:animateLayoutChanges="true"
    android:padding="0dp">

    <ImageView
        android:id="@+id/main_backBtn"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:src="@drawable/arrow_back_white"
        android:padding="4dp"
        android:layout_margin="8dp"/>

    <androidx.appcompat.widget.ActionMenuView
        android:id="@+id/main_topbar_menu"
        android:layout_width="wrap_content"
        android:layout_height="56dp"
        android:layout_alignParentRight="true"
        android:gravity="center_vertical|left"/>
</RelativeLayout>

在java中

ActionMenuView menuView = findViewById(R.id.main_topbar_menu);

MenuBuilder menuBuilder = (MenuBuilder) menuView.getMenu();
getActivity().getMenuInflater().inflate(R.menu.recieved_letter_commands, menuBuilder);

R.menu.recieved_letter_commands.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/letterCommand_delete"
        android:title="delete"
        android:icon="@drawable/ic_delete_white_24dp"
        app:showAsAction="always"
        android:iconTint="#777"/>
    <item
        android:id="@+id/letterCommand_archive"
        app:showAsAction="always"
        android:title="archive"
        android:icon="@drawable/ic_archive_income"
        android:iconTint="#777" />

    <item
        android:id="@+id/letterCommand_ref"
        android:title="Refrences"
        app:showAsAction="always"
        android:iconTint="#777"
        android:icon="@drawable/ic_reply_gray"/>

    <item
        android:id="@+id/letterCommand_receivers"
        android:title="Recievers"
        app:showAsAction="never"
        android:iconTint="#777"/>

    <item
        android:id="@+id/letterCommand_moveToFolder"
        android:title="Move To Folder..."
        app:showAsAction="never"
        android:iconTint="#777"/>

    <item
        android:id="@+id/letterCommand_setUnread"
        android:title="Set as unread"
        app:showAsAction="never"
        android:iconTint="#777"/>

    <item
        android:id="@+id/letterCommand_close"
        android:title="Close"
        app:showAsAction="never"
        android:iconTint="#777"/>

    <item
        android:id="@+id/letterCommand_note"
        android:title="Note"
        app:showAsAction="never"
        android:iconTint="#777"/>
</menu>
4

1 回答 1

0

您可以为溢出按钮使用自定义样式:

  1. 首先将 more_vert(3 个点)矢量图标添加到 res\drawable。
  2. 然后使用下面添加图标的样式,并对其进行填充
<style name="customoverflow">
    <item name="android:src">@drawable/ic_baseline_more_vert_24</item>
    <item name="android:paddingStart">32dp</item>
</style>

在主应用程序主题中应用样式:

<item name="android:actionOverflowButtonStyle">@style/customoverflow</item>
于 2021-10-13T01:16:41.717 回答