我开发一个应用程序,我想change the textcolor of the actionbar title
。现在,我定义我的表现一个主题:
<application
android:theme="@style/AppTheme">
</application>
这是在styles.xml定义:
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
<item name="android:textViewStyle">@style/AppTheme.TextView</item>
<item name="android:actionBarStyle">@style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="AppTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/themeapp</item>
</style>
<style name="AppTheme.TextView" parent="@android:style/Widget.TextView">
<item name="android:textColor">#FFFFFF</item>
</style>
这并不工作,但我不知道为什么。这应该根据this answer.neither TextView的风格正在工作。
我在做什么错?
UPDATE:改到符合以下格雷斯锋回答
使用SpannableString
我们可以设置Actionbar title
的文本颜色
SpannableString s = new SpannableString(title);
s.setSpan(new ForegroundColorSpan(Color.GREEN), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
getSupportActionBar().setTitle(s);
我不知道解决的办法,但我可以改变白色和黑色之间的文本颜色用这种方法。
所以,在styles.xml您有:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#FF4081</item>
</style>
</resources>
如果你改变什么父=“...”,以深色或浅色的主题里面,它适应文本颜色这些主题。例如,现在你有一个黑暗的主题,而文字是白色的,但是当我更改为“Theme.AppCompat.Light”文本颜色变为黑色。
希望这有助于以某种方式。
更改Activity
主题为:
<style name="ThemeName" parent="android:Theme.Holo.Light">
<item name="android:actionMenuTextColor">@color/white</item>
</style>
只是有这个问题,终于想通了。在你style.xml不指定您的工具栏的背景颜色。然后定义每个layout.xml文件的颜色:
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#B678EE"
android:elevation="4dp"
android:theme="@style/ToolbarTheme"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
这使您可以灵活地能够很容易地根据各自的活动如果需要的话,以及不同的操作栏的颜色。
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
<style name="AppTheme.TextView" parent="android:Widget.TextView">
你错过了一个符号“@”在这里?
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
也
<style name="AppTheme.TextView" parent="@android:Widget.TextView">
只需添加app:titleTextColor="@color/CUSTOM_COLOR"
像这样:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/yellow_light"
app:titleTextColor="@color/CUSTOM_COLOR"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
我假设你正在使用ToolBar
作为ActionBar
。所有的答案,我认为这是最容易实现的一个。并适用于所有版本的API。
所以在这里,它是:
操作栏标题使用textColorPrimary
作为其文本的颜色。因此,要改变在styles.xml创建与textColorPrimary
项新的样式,并设置任何你需要的颜色。
<style name="appBarTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:textColorPrimary">@color/colorRed</item>
</style>
现在,添加风格为您的主题在XML工具栏。
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="enterAlways"
android:id="@+id/toolbar"
android:theme="@style/appBarTheme">
</android.support.v7.widget.Toolbar>
现在你得到了你所需要的。
四处游荡的StackOverflow我发现this answer这最后的工作。
我在这里提出检举:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/ActionBar</item>
...
</style>
<style name="ActionBar" parent="@android:style/Widget.ActionBar">
<item name="android:titleTextStyle">@style/ActionBar.Title</item>
<item name="android:subtitleTextStyle">@style/ActionBar.Subtitle</item>
...
</style>
<style name="ActionBar.Title">
<item name="android:textColor">@color/my_color</item>
</style>
<style name="ActionBar.Subtitle">
<item name="android:textColor">@color/my_color</item>
</style>
当我得到了同样的问题,我用:
<item name="titleTextStyle">@style/ActionBarTextStyle</item>
<item name="android:titleTextStyle">@style/ActionBarTextStyle</item>
我觉得这只是你activity.I使用相同的代码,你的问题,它works.
首先,我用AppCompatActivity为基础的活动,并得到错误。然后我用的活性和它的作品。在我看来,你的代码是用于主题Theme.Holo,现在我们使用Theme.AppCompat。所以,如果你想改变,只是参考Changing Background and text color of AppCompat Light DarkActionBar Theme on android。它适用于me.Good运气你。
好像你已经使用style
的theme
代替。 Styles and themes differ。所以更换
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
同
<style name="AppTheme" parent="android:Theme.Light">