如何更改动作栏的文本颜色?我继承了Holo光主题,我能够改变动作栏的背景,但我不知道什么是属性调整来改变文本颜色。
好,我能够改变文本颜色与属性android:textColorPrimary但它也改变了文本颜色的下拉菜单显示时,溢出发生在动作栏按钮。知道如何改变那些下拉菜单/列表的颜色吗?
如何更改动作栏的文本颜色?我继承了Holo光主题,我能够改变动作栏的背景,但我不知道什么是属性调整来改变文本颜色。
好,我能够改变文本颜色与属性android:textColorPrimary但它也改变了文本颜色的下拉菜单显示时,溢出发生在动作栏按钮。知道如何改变那些下拉菜单/列表的颜色吗?
当前回答
<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]
其他回答
对于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]
这是一个老话题,但对于未来的读者来说,使用工具栏使一切变得非常简单:
Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
toolbar.setTitle(R.string.app_name);
toolbar.setTitleTextColor(getResources().getColor(R.color.someColor));
setSupportActionBar(toolbar);
找到了一种方法,可以很好地做到这一点,而无需在API >= 21上创建自己的布局。
它只会在操作栏中对文本和控件绘图进行着色。
希望对别人有用。
<!--Material design primary colors-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:navigationBarColor">@color/primary_dark</item>
<item name="actionBarTheme">@style/AppBaseTheme.Toolbar</item>
</style>
<!--Action bar-->
<style name="AppBaseTheme.Toolbar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="android:textColorPrimary">@color/action_bar_text</item>
<item name="colorControlNormal">@color/action_bar_text</item>
</style>
如果您正在使用自定义操作栏,您可以使用这些属性:
app:titleTextColor="@color/...."
app:subtitleTextColor="@color/...."
或者用这样的方法:
setTitleTextColor()
欲了解更多属性,请查看此链接