如何在工具栏中制作菜单的圆角

如何在工具栏中制作菜单的圆角

本文介绍了如何在工具栏中制作菜单的圆角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这是我的toolbar.xml

This is my toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/_40sdp"
    android:background="@android:color/holo_red_dark"
    android:gravity="center_vertical"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:popupTheme="@style/PopUpTheme"/>

这就是我在 style.xml 中自定义弹出菜单的方式

This is how I customized the popup menu in style.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="PopUpTheme" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:popupBackground">@drawable/background_popup_menu</item>
    </style>
</resources>

background_popup_menu.xml

background_popup_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/white" />
    <corners android:radius="5dp" />
</shape>

这就是我最终得到的.

但我需要这样做

推荐答案

您可以更改在应用主题中定义 actionOverflowMenuStyle 属性的溢出菜单的背景.

You can change the background of the overflow menu defining in your app theme the actionOverflowMenuStyle attribute.

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
   <item name="actionOverflowMenuStyle">@style/popupOverflowMenu</item>
</style>

与:

  <style name="popupOverflowMenu" parent="@style/Widget.MaterialComponents.PopupMenu.Overflow">
    <item name="android:popupBackground">@drawable/my_mtrl_popupmenu_background</item>
  </style>

然后定义 drawable/my_mtrl_popupmenu_background.xml 如下:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="?attr/colorSurface"/>

  <corners
      android:bottomLeftRadius="8dp"
      android:bottomRightRadius="8dp"
      android:topLeftRadius="8dp"
      android:topRightRadius="8dp"/>

</shape>

这篇关于如何在工具栏中制作菜单的圆角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:41