更改工具栏菜单项目颜色(非隐藏操作)(Change Toolbar Menu Item color (non

系统教程 行业动态 更新时间:2024-06-14 16:57:40
更改工具栏菜单项目颜色(非隐藏操作)(Change Toolbar Menu Item color (non-hidden action))

假设我有一个菜单(options_menu.xml)类似于以下内容:

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" > <item android:id="@+id/action_login" android:title="Login" app:showAsAction="always"/> </menu>

我膨胀到新的工具栏项目中

mToolbar.inflateMenu(R.menu.options_home);

这导致了类似的结果

有没有办法在使用图像的情况下更改此文本颜色,更改工具栏文本颜色的其余部分,还是通过将自定义视图添加到工具栏? 寻找minSdk 15(appcompat)的答案。

更新:

我的相关风格:

<style name="AppTheme" parent="AppTheme.Base"> <item name="actionMenuTextColor">@color/ww_red</item> </style> <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/red</item> <item name="colorAccent">@color/theme_accent</item> <item name="android:textColor">@color/text_dark</item> <item name="android:colorEdgeEffect">@color/gray</item> </style>

Say I have a menu (options_menu.xml) similar to the following:

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" > <item android:id="@+id/action_login" android:title="Login" app:showAsAction="always"/> </menu>

which I inflate into the new Toolbar item

mToolbar.inflateMenu(R.menu.options_home);

This results in something like

Is there a way to change this text color without using an image, changing the rest of the Toolbar text color, or by adding a custom view to the toolbar? Looking for an answer for minSdk 15 (appcompat).

Update:

My relevant style:

<style name="AppTheme" parent="AppTheme.Base"> <item name="actionMenuTextColor">@color/ww_red</item> </style> <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/red</item> <item name="colorAccent">@color/theme_accent</item> <item name="android:textColor">@color/text_dark</item> <item name="android:colorEdgeEffect">@color/gray</item> </style>

最满意答案

在你的主题文件中,你必须这样做:

<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar"> ... <item name="actionMenuTextColor">@color/text_color</item> ... </style>

并将此主题应用于您的工具栏视图,如下所示:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:layout_gravity="top" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" android:theme="@style/AppTheme.ActionBar"/>

android:theme =“@ style / AppTheme.ActionBar”不要忘记你的工具栏中的这一行

In your theme file you have to put this :

<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar"> ... <item name="actionMenuTextColor">@color/text_color</item> ... </style>

and apply this theme to your Toolbar view like this :

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:layout_gravity="top" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" android:theme="@style/AppTheme.ActionBar"/>

android:theme="@style/AppTheme.ActionBar" don't forget this line in your toolbar

更多推荐

android,<item,电脑培训,计算机培训,IT培训"/> <meta name="description&

本文发布于:2023-04-13 12:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/7cf645785458358d47a8de22646fe73e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工具栏   菜单   颜色   操作   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!