如何自定义操作栏字幕字体? [英] How to customize the Action Bar subtitle Font?
问题描述
我已经创建了一个动作条( android.support.v7.widget.Toolbar
),如下图所示。
I have created an ActionBar (android.support.v7.widget.Toolbar
) as below.
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
在我的动作条,标题以外,我也有字幕。不过,我想自定义的字幕。在自定义,我指的是字体大小,颜色和字体。
In my ActionBar, other than the title, I also have Subtitle. However I would like to customize the Subtitle. In customize, I mean the font size, color and typeface.
我已经通过各种主题和风格,仍然未果。
I've tried through various Theme and Style, and still unsuccessful.
如果有,如何可以做一个简单的完整的例子,这将真正帮助。谢谢!
If there's a simple complete example of how that could be done, that would really help. Thanks!
推荐答案
如果你还没有在你的布局文件这个命名空间属性添加:
If you don't already have this namespace attribute in your layout file add it:
的xmlns:程序=http://schemas.android.com/apk/res-auto
xmlns:app="http://schemas.android.com/apk/res-auto"
更新您的工具栏在布局文件属性是这样的:
Update your Toolbar attributes in your layout file like this:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleTextAppearance="@style/ToolbarTitleAppearance"
app:subtitleTextAppearance="@style/ToolbarSubtitleAppearance"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
样式添加这样的:
Add styles like these:
<style name="ToolbarTitleAppearance" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">20dp</item>
<!-- include other attributes you want to change: textColor, textStyle, etc -->
</style>
<style name="ToolbarSubtitleAppearance" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle">
<item name="android:textSize">14dp</item>
</style>
这篇关于如何自定义操作栏字幕字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!