如何更改字体大小使用的主题为ActionBarSherlock操作栏的标题?
我此刻的主题(适用于我的整个应用如下):
<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>
注意,当在我的应用程序的所有视图设置字体大小设置。 只是没有ActionBar的字体。
如果您只是需要更改标题的风格,你可以添加像这样的自定义视图:
<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" />
然后隐藏实际的标题和显示自定义视图。
_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);
就这样! 如果你有兴趣什么是动作条标题的默认字体大小是18SP。
我通过使用下面的主题得到了这个工作:
<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>
注意文本大小是在样式命名MyApp.ActionBar.TextAppearance
。 此外,根据ActionBarSherlock的主题应在两个机器人前缀属性和正常的属性进行设置(见上文风格Theme.MyApp.Default actionBarStyle。)