Android在标题Material Design中设置自定义字体

时间:2015-08-01 11:30:34

标签: android material-design custom-font

我想更改自定义工具栏的字体。

我的问题是,这不是一个静态的文本视图。我尝试使用这样的Spannable String:

    SpannableString s = new SpannableString("My Title");
    s.setSpan(new TypefaceSpan(this, "font.otf"), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);


    collapsingToolbarLayout.setTitle(s);

但它不会起作用:-( 在图片中你可以看到它的样子......

http://www.directupload.net/file/d/4066/ye8tcshb_png.htm

http://www.directupload.net/file/d/4066/oh7t6ddv_png.htm

感谢您的回答: - )

1 个答案:

答案 0 :(得分:2)

尝试以下代码

TextView newfont;
newfont=(TextView) findViewById(R.id.textView1);
Typeface font=Typeface.createFromAsset(getAssets(), "fonts/font.ttf");
newfont.setTypeface(font);
newfont.setText("This is the new font Text");

当然将font.ttf文件放在assets/fonts文件夹中。

请注意,TextView中的Toolbar与任何其他TextView一样。

Read more from here

相关问题