繁体   English   中英

如何更改ActionBarSherlock上的字体样式

[英]How can I change the font style on 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>

请注意,我的应用程序中的所有视图都设置了字体大小设置。 只是不是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);

就这样! 如果你感兴趣的是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>

请注意,Text大小位于名为MyApp.ActionBar.TextAppearance的样式中。 另外根据ActionBarSherlock ,主题应该设置在android前缀属性和普通属性上(参见上面样式Theme.MyApp.Default中的actionBarStyle。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM