How to change font style on ActionBarSherlock

How to change the font size for the title of the action bar using Themes for ActionBarSherlock?

My theme is currently (applies to my entire application:

<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> 

Please note that the font size is set as set in all views in my application. Just not an ActionBar font.

+7
source share
2 answers

I got this work using the following topic:

 <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 size of the text in the style named MyApp.ActionBar.TextAppearance . Also, in accordance with ActionBarSherlock, the theme should be set for both prefixed attributes and regular attributes (see ActionBarStyle in Theme.MyApp.Default style above.)

+7
source

If you just need to change the style of the header, you can add a custom view as follows:

 <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 name 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); 

It's all! If you're interested, what is the default font size for the ActionBar name is 18sp.

+10
source

All Articles