我想将工具栏标题的字体系列更改为sans-serif-smallcaps。我该怎么做?
我AppTheme有父母Theme.AppCompat.Light.DarkActionBar
编辑:工具栏XML:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
Run Code Online (Sandbox Code Playgroud)
小智 9
我的版面页面:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
转到您的styles.xml, 然后添加您的字体(这在Android Studio 3.0中有效)
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" >
<item name="android:fontFamily">@font/handlee_regular</item>
/// change your font
</style>
Run Code Online (Sandbox Code Playgroud)
效果很好。
mToolbar.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
View view = mToolbar.getChildAt(0);
if (view != null && view instanceof TextView) {
TextView title = (TextView) view;
AssetManager mgr = getAssets();
Typeface tf = Typeface.createFromAsset(mgr, "ttf.ttf");//Font file in /assets
title.setTypeface(tf);
mToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7091 次 |
| 最近记录: |