如何更改Android中PopMenu(材料设计3)的图标颜色?
我正在尝试在我的应用中在此之后在我的应用中实现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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了最佳(甚至可以支持夜间模式)
我以前搜索了解决此问题的解决方案,并在菜单中 。xml文件
在下面的示例中,菜单_items_options.xml
添加
您可以更改为您想要的“?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
add
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"