How do I change the font size for the title of the Action bar using Themes for ActionBarSherlock?
My theme at the moment (applied to my whole application is as follows):
<style name="Theme.MyAppDefaults" parent="@style/Theme.Sherlock.Light">
<item name="android:textSize">@dimen/default_textsize</item>
<item name="actionBarSize">@dimen/action_bar_height</item>
</style>
Notice that the font size is set as set on all the Views in my app. Just not the ActionBar's font.
If you need to just change the title's style you can add a custom view with like this:
<TextView
android:id="@+id/action_custom_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Custom title"
android:textColor="#fff"
android:textSize="18sp" />
Then hide the actual title and show the custom view.
_actionBar.setDisplayShowTitleEnabled(false);
LayoutInflater inflater = LayoutInflater.from(this);
View customView = inflater.inflate(R.layout.custom_action_layout, null);
TextView titleTV = (TextView) customView.findViewById(R.id.action_custom_title);
// you can apply a custom typeface here or do sth else...
_actionBar.setCustomView(customView);
_actionBar.setDisplayShowCustomEnabled(true);
That's all! If you are interested what is the default font size for ActionBar title it's 18sp.
I got this working by using the below theme:
<style name="Theme.MyApp.Default" parent="@style/Theme.Sherlock.Light">
<item name="actionBarStyle">@style/MyApp.SherlockActionBarStyle</item>
<item name="android:actionBarStyle">@style/MyApp.SherlockActionBarStyle</item>
</style>
<style name="MyApp.SherlockActionBarStyle" parent="@style/Widget.Sherlock.ActionBar">
<item name="titleTextStyle">@style/MyApp.ActionBar.TextAppearance</item>
</style>
<style name="MyApp.ActionBar.TextAppearance" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textSize">@dimen/default_textsize</item>
<item name="android:textColor">@color/dark_grey</item>
</style>
Notice the Text size is in the style named MyApp.ActionBar.TextAppearance
. Also according to ActionBarSherlock the theme should be set on both android prefixed attributes and normal attributes (See actionBarStyle in style Theme.MyApp.Default above.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With