android工具栏上的自定义字体
我有自己的工具栏,我想为我的标题自定义字体,但我没有得到它的工作android工具栏上的自定义字体,android,android-toolbar,Android,Android Toolbar,我有自己的工具栏,我想为我的标题自定义字体,但我没有得到它的工作 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); SpannableString title = new SpannableString(getResources().getString(R.string.app_name)); title.setSpan(Typeface.createFromAs
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
SpannableString title = new SpannableString(getResources().getString(R.string.app_name));
title.setSpan(Typeface.createFromAsset(getAssets(), "KeepCalm-Medium.ttf"), 0, title.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
toolbar.setTitle(title);
setSupportActionBar(toolbar);
我认为我做得对,但它什么也没做。你可以使用
工具栏内的文本视图来做<代码>工具栏
只是一个视图组
:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Toolbar Title"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "KeepCalm-Medium.ttf");
toolbarTitle.setTypeface(myTypeface);