如何更改Android中PopMenu(材料设计3)的图标颜色?

发布于 2025-02-13 13:30:20 字数 1485 浏览 3 评论 0原文

我正在尝试在我的应用中在此之后在我的应用中实现popupmenu a>。 它有效,但我无法更改图标颜色。我将如何实现?

同时,我可以更改背景颜色:

<style name="Theme.MyApp" parent="Theme.Material3.DayNight.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorBackground</item>
    <item name="android:navigationBarColor">@color/colorWhite</item>
    <item name="android:windowBackground">@color/colorBackground</item>

    <item name="popupMenuStyle">@style/Widget.App.PopupMenu</item>

    <item name="colorControlNormal">@color/colorSecondary</item> // <--- This one has no effect
</style>

<style name="Widget.App.PopupMenu" parent="Widget.Material3.PopupMenu">
    <item name="android:popupBackground">@drawable/menu_back</item> // <-- This changes background and it works good.
    <item name="colorControlNormal">@color/colorSecondary</item> // <--- Even placed here still doesn't work
    <item name="android:colorControlNormal">@color/colorSecondary</item> // <-- even with android:
</style>

我正在使用Google的新材料设计3库。

另外,我尝试在Internet上找到一些东西,并且只能在工具栏上找到有关popupmenu的解决方案,这不是我的情况。我需要一个popupmenu单击按钮时。

I am trying to implement a PopupMenu in my app following this example.
It works, but I can't change the icon color. How would I achieve that?

Meanwhile I could change the background color:

<style name="Theme.MyApp" parent="Theme.Material3.DayNight.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorBackground</item>
    <item name="android:navigationBarColor">@color/colorWhite</item>
    <item name="android:windowBackground">@color/colorBackground</item>

    <item name="popupMenuStyle">@style/Widget.App.PopupMenu</item>

    <item name="colorControlNormal">@color/colorSecondary</item> // <--- This one has no effect
</style>

<style name="Widget.App.PopupMenu" parent="Widget.Material3.PopupMenu">
    <item name="android:popupBackground">@drawable/menu_back</item> // <-- This changes background and it works good.
    <item name="colorControlNormal">@color/colorSecondary</item> // <--- Even placed here still doesn't work
    <item name="android:colorControlNormal">@color/colorSecondary</item> // <-- even with android:
</style>

I am using the new Material Design 3 library from Google.

Also, I tried to find something on Internet and I could only find solutions for my issue regarding PopupMenu on Toolbar, which is not my case. I need a PopupMenu when a button is clicked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那些过往 2025-02-20 13:30:20

找到了最佳(甚至可以支持夜间模式)

我以前搜索了解决此问题的解决方案,并在菜单中 。xml文件
在下面的示例中,菜单_items_options.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/menu_share"
        android:title="share"
        android:icon="@drawable/round_ios_share_24"
        app:iconTint="?attr/colorOnSurface"
        />

    <item
        android:id="@+id/menu_select"
        android:title="select"
        android:icon="@drawable/round_select_all_24"
        app:iconTint="?attr/colorOnSurface"
        />

</menu>

添加

app:iconTint="?attr/colorOnSurface"

您可以更改为您想要的“?attr/coloronsurface”颜色(最好使用我提到的内容),以便在白天和黑夜模式下获得更好的体验

:“ app:icontint”不是“ android:icontint”

I previously searched for a solution to this problem and found this solution the best (even night mode can be supported)

in your menu.xml file
In the following example it menu_items_options.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/menu_share"
        android:title="share"
        android:icon="@drawable/round_ios_share_24"
        app:iconTint="?attr/colorOnSurface"
        />

    <item
        android:id="@+id/menu_select"
        android:title="select"
        android:icon="@drawable/round_select_all_24"
        app:iconTint="?attr/colorOnSurface"
        />

</menu>

add

app:iconTint="?attr/colorOnSurface"

You can change to the "?attr/colorOnSurface" color you want (and it is better to use what I mentioned) for a better experience with day and night mode

Note: "app:iconTint" Not "android:iconTint"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文