【问题标题】:Change app's title color from an actionbar created on actionbarstylegenerator从在操作栏样式生成器上创建的操作栏更改应用标题颜色
【发布时间】:2013-09-06 01:41:09
【问题描述】:

我正在尝试在我的样式中使用 android:textColor 将我的操作栏 (sherlock) 应用标题颜色从黑色更改为白色,但它似乎不起作用。

我在http://jgilfelt.github.io/android-actionbarstylegenerator 上生成了这个操作栏,但我认为 textColor 代码应该可以正常工作。

这是我从网站上获得的代码。我要怎么做才能让标题变成白色?

<!-- ActionBar from Generator -->
<style name="Theme.xotab" parent="@style/Theme.xot">
    <item name="actionBarItemBackground">@drawable/selectable_background_xotab</item>
    <item name="popupMenuStyle">@style/PopupMenu.xotab</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.xotab</item>
    <item name="actionBarTabStyle">@style/ActionBarTabStyle.xotab</item>
    <item name="actionDropDownStyle">@style/DropDownNav.xotab</item>
    <item name="actionBarStyle">@style/ActionBar.Solid.xotab</item>
    <item name="actionModeBackground">@drawable/cab_background_top_xotab</item>
    <item name="actionModeSplitBackground">@drawable/cab_background_bottom_xotab</item>
    <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.xotab</item>
</style>

<style name="ActionBar.Solid.xotab" parent="@style/Widget.Sherlock.Light.ActionBar.Solid">
    <item name="background">@drawable/ab_solid_xotab</item>
    <item name="backgroundStacked">@drawable/ab_stacked_solid_xotab</item>
    <item name="backgroundSplit">@drawable/ab_bottom_solid_xotab</item>
    <item name="progressBarStyle">@style/ProgressBar.xotab</item>
</style>

<style name="ActionBar.Transparent.xotab" parent="@style/Widget.Sherlock.Light.ActionBar">
    <item name="background">@drawable/ab_transparent_xotab</item>
    <item name="progressBarStyle">@style/ProgressBar.xotab</item>
</style>

<style name="PopupMenu.xotab" parent="@style/Widget.Sherlock.Light.ListPopupWindow">
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_xotab</item>
</style>

<style name="DropDownListView.xotab" parent="@style/Widget.Sherlock.Light.ListView.DropDown">
    <item name="android:listSelector">@drawable/selectable_background_xotab</item>
</style>

<style name="ActionBarTabStyle.xotab" parent="@style/Widget.Sherlock.Light.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator_ab_xotab</item>
</style>

<style name="DropDownNav.xotab" parent="@style/Widget.Sherlock.Light.Spinner.DropDown.ActionBar">
    <item name="android:background">@drawable/spinner_background_ab_xotab</item>
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_xotab</item>
    <item name="android:dropDownSelector">@drawable/selectable_background_xotab</item>
</style>

<style name="ProgressBar.xotab" parent="@style/Widget.Sherlock.Light.ProgressBar.Horizontal">
    <item name="android:progressDrawable">@drawable/progress_horizontal_xotab</item>
</style>

<style name="ActionButton.CloseMode.xotab" parent="@style/Widget.Sherlock.Light.ActionButton.CloseMode">
    <item name="android:background">@drawable/btn_cab_done_xotab</item>
</style>

<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.xotab.Widget" parent="@style/Theme.Sherlock">
    <item name="popupMenuStyle">@style/PopupMenu.xotab</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.xotab</item>
</style>

【问题讨论】:

  • 您在哪个 API 级别进行测试?
  • 使用 Google API 编译 18
  • 那么,您正在测试的设备/模拟器的 Android 版本是什么?
  • 有人有真正的解决方案吗?使用代码似乎是一种 hack。

标签: android android-layout actionbarsherlock android-actionbar


【解决方案1】:

您可以在 onCreate 中通过代码以更简单的方式完成此操作:

int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
TextView Tv = (TextView)findViewById(titleId);
Tv.setTextColor(colorID);

【讨论】:

  • 2.3 不支持,这个版本有替代方案吗?
猜你喜欢
  • 1970-01-01
  • 2014-08-19
  • 2013-04-20
  • 1970-01-01
  • 1970-01-01
  • 2015-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多