如何更改动作栏的文本颜色?我继承了Holo光主题,我能够改变动作栏的背景,但我不知道什么是属性调整来改变文本颜色。
好,我能够改变文本颜色与属性android:textColorPrimary但它也改变了文本颜色的下拉菜单显示时,溢出发生在动作栏按钮。知道如何改变那些下拉菜单/列表的颜色吗?
如何更改动作栏的文本颜色?我继承了Holo光主题,我能够改变动作栏的背景,但我不知道什么是属性调整来改变文本颜色。
好,我能够改变文本颜色与属性android:textColorPrimary但它也改变了文本颜色的下拉菜单显示时,溢出发生在动作栏按钮。知道如何改变那些下拉菜单/列表的颜色吗?
当前回答
如果您正在使用自定义操作栏,您可以使用这些属性:
app:titleTextColor="@color/...."
app:subtitleTextColor="@color/...."
或者用这样的方法:
setTitleTextColor()
欲了解更多属性,请查看此链接
其他回答
对于Android 5(棒棒糖),你必须使用Android:actionBarPopupTheme来设置溢出菜单的textColor。
<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/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_primary"
android:theme="@style/GalaxyZooThemeToolbarDarkOverflow"
app:popupTheme="@style/Theme.AppCompat.NoActionBar" />
<style name="GalaxyZooThemeToolbarDarkOverflow" parent="Theme.AppCompat.NoActionBar">
<!-- android:textColorPrimary is the color of the title text
in the Toolbar, in the Theme.AppCompat theme: -->
<item name="android:textColorPrimary">@color/abc_primary_text_material_light</item>
<!-- android:textColorPrimaryInverse is the color of the title
text in the Toolbar, in the Theme.AppCompat.Light theme: -->
<!-- <item name="android:textColorPrimaryInverse">@color/abc_primary_text_material_light</item> -->
<!-- android:actionMenuTextColor is the color of the text of
action (menu) items in the Toolbar, at least in the
Theme.AppCompat theme.
For some reason, they already get the textColorPrimary
when running on API 21, but not on older versions of
Android, so this is only necessary to support older
Android versions.-->
<item name="actionMenuTextColor">@color/abc_primary_text_material_light</item>
<!-- android:textColorSecondary is the color of the menu
overflow icon (three vertical dots) -->
<item name="android:textColorSecondary">@color/abc_secondary_text_material_light</item>
<!-- This would set the toolbar's background color,
but setting this also changes the popup menu's background,
even if we define popupTheme for our <Toolbar> -->
<!-- <item name="android:background">@color/color_primary</item> -->
</style>
**Reference:**
[https://www.murrayc.com/permalink/2014/10/28/android-changing-the-toolbars-text-color-and-overflow-icon-color/][1]
尝试了很多方法,在低版本的API中,一个可行的方法是<item name="actionMenuTextColor">@color/your_color</item>,不要使用Android命名空间,希望可以帮助到你
ps:
<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>
<item name="actionMenuTextColor">@color/actionMenuTextColor</item>
</style>
很多答案已弃用,所以我将更新线程,并展示如何在ActionBar(工具栏)和ActionBar弹出菜单中更改文本颜色和背景色。
在Android中(截至2018年5月)使用操作栏(工具栏)的最新方法是使用主题和NoActionBar,而不是使用工具栏。
这就是你所需要的:
In Activity (which extends AppCompatActivity) declare Toolbar: Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(myToolbar); Add Toolbar in the Activity's layout xml. Here we will set our custom (overwritten themes), note android:theme="@style/ThemeOverlay.AppTheme.ActionBar" and app:popupTheme="@style/ThemeOverlay.AppTheme.PopupMenu", they will do the trick. <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" android:theme="@style/ThemeOverlay.AppTheme.ActionBar" app:popupTheme="@style/ThemeOverlay.AppTheme.PopupMenu" app:layout_constraintTop_toTopOf="parent" /> In your styles.xml you will have to overwrite those two styles to set custom colors: <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> <item name="actionBarTheme">@style/ThemeOverlay.AppTheme.ActionBar</item> <item name="actionBarPopupTheme">@style/ThemeOverlay.AppTheme.PopupMenu</item> </style> <style name="ThemeOverlay.AppTheme.ActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> <item name="android:textColorPrimary">@color/action_bar_text_color</item> <item name="android:background">@color/action_bar_bg_color</item> </style> <style name="ThemeOverlay.AppTheme.PopupMenu" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> <item name="android:background">@color/popup_bg_color</item> <item name="android:textColorPrimary">@color/popup_text_color</item> </style>
就是这样,伙计们
附注:如果你问我,我会说:是的,整个主题的事情是一团糟。
您可以直接在XML文件中使用HTML <font>属性更改任何文本的颜色。 例如在strings.xml中:
<resources>
<string name = "app_name">
<html><font color="#001aff">Multi</font></html>
<html><font color="#ff0044">color</font></html>
<html><font color="#e9c309">Text </font></html>
</string>
</resources>