假设我有一个菜单(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&
发布评论