How to set title color in ActionBarSherlock
?
Which theming attributes should I use?
How to set title color in ActionBarSherlock
?
Which theming attributes should I use?
From the ActionBarSherlock website
Parent Themes
In order for the custom action bar implementation to function your application must use Theme.Sherlock, Theme.Sherlock.Light, or Theme.Sherlock.Light.DarkActionBar, or your custom theme must use one of the aforementioned as its parent.
Mirrored Attributes
Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation...
In short, that means you need to leave out the android:
prefix when you're styling the ActionBar
.
Theming the title color
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YOURTHEME" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">@style/YOURTHEME.ActionBarStyle</item>
<item name="actionBarStyle">@style/YOURTHEME.ActionBarStyle</item>
</style>
<style name="YOURTHEME.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:titleTextStyle">@style/YOURTHEME.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">@style/YOURTHEME.ActionBar.TitleTextStyle</item>
</style>
<style name="YOURTHEME.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">@color/YOUR_COLOR</item>
<item name="textColor">@color/YOUR_COLOR</item>
</style>
</resources>
NOTE
I haven't tested this. Also, what have you tried? You should searching before posting on SO in the future.
You can easily do this with
getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>App Name</font>"));
From the ActionBarSherlock website
Parent Themes
In order for the custom action bar implementation to function your application must use Theme.Sherlock, Theme.Sherlock.Light, or Theme.Sherlock.Light.DarkActionBar, or your custom theme must use one of the aforementioned as its parent.
Mirrored Attributes
Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation...
In short, that means you need to leave out the android:
prefix when you're styling the ActionBar
.
Theming the title color
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YOURTHEME" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">@style/YOURTHEME.ActionBarStyle</item>
<item name="actionBarStyle">@style/YOURTHEME.ActionBarStyle</item>
</style>
<style name="YOURTHEME.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:titleTextStyle">@style/YOURTHEME.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">@style/YOURTHEME.ActionBar.TitleTextStyle</item>
</style>
<style name="YOURTHEME.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">@color/YOUR_COLOR</item>
<item name="textColor">@color/YOUR_COLOR</item>
</style>
</resources>
NOTE
I haven't tested this. Also, what have you tried? You should searching before posting on SO in the future.
i have changed the title color of this way:
in the Styles.xml file, i have added these styles
<style name="Theme.Styled" parent="@style/Theme.Sherlock.Light">
<item name="actionBarStyle">@style/CustomActionBarStyle</item>
<item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
</style>
<style name="CustomActionBarStyle" parent="@style/Widget.Sherlock.ActionBar">
<item name="titleTextStyle">@style/CustomTitleColorBar</item>
<item name="android:titleTextStyle">@style/CustomTitleColorBar</item>
</style>
<!-- Style for the color title bar -->
<style name="CustomTitleColorBar" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">@android:color/white</item>
</style>
the last thing that i did was set the theme in the activity:
public static int THEME = R.style.Theme_Styled;
this line goes before super.onCreate() method
setTheme(THEME);
this is it.
you can do it from 2 places either in style.xml or programatically
1.From style.xml
2.Or in code
int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
TextView yourTextView = (TextView)findViewById(titleId);
yourTextView.setTextColor(getResources().getColor(R.color.myColor));
Or using actionbar you can also achieve this
getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>App Name</font>"));
I think you are trying to change the text color that is on the Menu, not the color of text that is in the Title in ActionBarSherlock.
When you use getSupportActionBar().SetTitle("My Title")
to style this text you should use the code @Archie.bpgc
. His answer is correct, but I believe that you are in need of the following code:
<style name="MyTheme.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">24sp</item>
<item name="android:gravity">center</item>
</style>
See that you simply exchange parent =" TextAppearance.Sherlock.Widget.ActionBar.Title">
with parent = "TextAppearance.Sherlock.Widget.ActionBar.Menu">
© 2022 - 2024 — McMap. All rights reserved.