如果您只需要更改标题的样式,您可以添加一个自定义视图,如下所示:
<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。