如何更改动作栏的文本颜色?我继承了Holo光主题,我能够改变动作栏的背景,但我不知道什么是属性调整来改变文本颜色。
好,我能够改变文本颜色与属性android:textColorPrimary但它也改变了文本颜色的下拉菜单显示时,溢出发生在动作栏按钮。知道如何改变那些下拉菜单/列表的颜色吗?
如何更改动作栏的文本颜色?我继承了Holo光主题,我能够改变动作栏的背景,但我不知道什么是属性调整来改变文本颜色。
好,我能够改变文本颜色与属性android:textColorPrimary但它也改变了文本颜色的下拉菜单显示时,溢出发生在动作栏按钮。知道如何改变那些下拉菜单/列表的颜色吗?
当前回答
好吧,我找到了一个更好的办法。我现在只能改变标题的颜色。你也可以调整副标题。
下面是我的styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/red</item>
</style>
</resources>
其他回答
好吧,我找到了一个更好的办法。我现在只能改变标题的颜色。你也可以调整副标题。
下面是我的styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/red</item>
</style>
</resources>
尝试了很多方法,在低版本的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 ID不是直接可用的,所以你必须做一点hack。
int actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
if (actionBarTitleId > 0) {
TextView title = (TextView) findViewById(actionBarTitleId);
if (title != null) {
title.setTextColor(Color.RED);
}
}
很多答案已弃用,所以我将更新线程,并展示如何在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>
就是这样,伙计们
附注:如果你问我,我会说:是的,整个主题的事情是一团糟。
试着在Activity的onCreate中添加这个。适用于几乎所有Android版本。
actionBar.setTitle(Html.fromHtml("<font color='#ffff00'>Your Title</font>"));
or
getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffff00'>Your Title</font>"));