Die*_*rik 7 android actionbarsherlock
如何使用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>
Run Code Online (Sandbox Code Playgroud)
请注意,我的应用程序中的所有视图都设置了字体大小设置.只是不是ActionBar的字体.
lom*_*mza 10
如果您只需要更改标题的样式,可以添加如下自定义视图:
<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" />
Run Code Online (Sandbox Code Playgroud)
然后隐藏实际标题并显示自定义视图.
_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);
Run Code Online (Sandbox Code Playgroud)
就这样!如果你感兴趣的是ActionBar标题的默认字体大小是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>
Run Code Online (Sandbox Code Playgroud)
请注意,文本大小位于命名的样式中MyApp.ActionBar.TextAppearance.另外根据ActionBarSherlock,主题应该设置在android前缀属性和普通属性上(参见上面样式Theme.MyApp.Default中的actionBarStyle.)