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>

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

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...