luk*_*ris 3 android android-appcompat android-toolbar
我正在尝试更改工具栏标题的字体。这是我的工具栏布局:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#666666"
app:titleTextAppearance="@style/MyText"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
Run Code Online (Sandbox Code Playgroud)
在我的 styles.xml 中
<style name="MyText">
<item name="fontPath">fonts/myFont.ttf</item>
</style>
Run Code Online (Sandbox Code Playgroud)
如果我不设置app:titleTextAppearance
,工具栏使用系统字体。我设置后,字体变小了,但是还是系统字体。难道我做错了什么?
任何建议、评论或答案都非常感谢。
我尝试将样式移至styles-text.xml
但没有运气
目前,我使用 SpannableString 和TypefaceSpan来完成这项工作。希望它能帮助某人。
这有效:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:titleTextAppearance="@style/ActionBarTitleStyle"/>
Run Code Online (Sandbox Code Playgroud)
然后将其放入您的 styles.xml 中
<style name="ActionBarTitle" parent="android:Widget.TextView">
<!-- The action bar title font -->
<item name="android:fontFamily">sans-serif-light</item>
<!-- Customizes the color of the action bar title-->
<item name="android:textColor">#FF0000</item>
<!-- Customizes the size of the action bar title-->
<item name="android:textSize">24sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4925 次 |
最近记录: |