我尝试在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.
是你的TF不为空? – 2014-11-14 15:27:26