Android自定义字体加载错误
问题描述:
我尝试在textview中使用roboto黑色字体,但tx.setTypeface(tf);
正在引发错误。它说,“Syntax error on token(s), misplaced construct(s)
”,并在(tf)
“Syntax error on token "tf", VariableDeclaratorId expected after this token
”。Android自定义字体加载错误
下面是我使用来改变字体的代码片段:
TextView tx = (TextView) findViewById(R.id.moomoo);
Typeface tf = Typeface.createFromAsset(getAssets(), "Roboto-Black.ttf");
tx.setTypeface(tf);
据我所知,我只需要改变java文件,同时具有在我的资产文件夹中的TTF字体文件,在名为“字体”的资产文件夹的子项中。然后我只需要一个对文本视图的引用,并且可以从java类的构造函数中为我想要更改的xml文件的字体执行所有操作,对吗?我的逻辑是否有缺陷,我做错了什么? Android是版本19.
答
变化
Typeface tf = Typeface.createFromAsset(getAssets(), "Roboto-Black.ttf");
到
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Black.ttf");
+0
这对我有很大的帮助,也没有在我的Android应用程序的构造中,我已经把它放在构造函数的下面,忘记包含它,但移动了支架。再次感谢您的帮助! – Davep 2014-11-14 19:14:12
是你的TF不为空? – 2014-11-14 15:27:26