我无法更改操作栏标题的文字颜色。如何在xml中完成?
我在style-v11和values-v14中的style.xml包含这段代码
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">showTitle</item>
<item name="titleTextStyle">@style/titleStyle</item>
</style>
<style name="titleStyle" parent="@style/TextAppearance.AppCompat.Widget.Base.ActionBar.Title">
<item name="android:textColor">#f2dca9</item>
</style>
</resources>
答案 0 :(得分:2)
请试试这个。有用 你,把这段代码放在onCreate()方法
中ActionBar bar = getActionBar();
bar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBartitle </font>"));
或将其添加到操作栏的根目录
<style name="ActionBar" parent="@style/Theme.AppCompat.Light">
<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
<item name="actionMenuTextColor">@color/stdDarkBlueText</item>
</style>
<style name="Widget.Styled.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="titleTextStyle">@style/ActionBarTitleText</item>
<item name="subtitleTextStyle">@style/ActionBarSubTitleText</item>
</style>
<style name="ActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/stdDarkBlueText</item>
<item name="android:textSize">12sp</item>
</style>
<style name="ActionBarSubTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle">
<item name="android:textColor">@color/stdDarkBlueText</item>
<item name="android:textSize">12sp</item>
答案 1 :(得分:1)
试试这个
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
<item name="android:displayOptions">showTitle</item>
<item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#f2dca9</item>
</style>
答案 2 :(得分:0)
以编程方式执行,
int titleId = this.activity.getResources().getIdentifier("action_bar_title", "id", "android");
TextView abTitle = (TextView) this.activity.findViewById(titleId);
abTitle.setTextColor(Color.parseColor("#6f6f6f"));
使用XML:
<resources>
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:titleTextStyle">@style/TitleBarTextColor</item>
</style>
<style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/red</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
如果您使用API 14和UP,则将其放入值-v14 .....
多数民众赞成......