嗨我正在尝试更改TextView
的字体样式。我知道如何改变它,我在使用下面的代码之前完成了这个工作。文字视图中的Android设置字体
public class Main_Activity extends ListActivity {
Typeface myNewFace = Typeface.createFromAsset(getAssets(),
"fonts/bediz__.ttf");
private CustomListAdapter adap;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adap = new CustomListAdapter(this);
setListAdapter(adap);
}
public static class CustomListAdapter extends BaseAdapter implements
Filterable {
public View getView(final int position, View convertView,
ViewGroup parent) {
textView.setText(prayers[position]);
holder.textLine.setTypeface(myNewFace);
}
}
一些我跳过,因为没有必要,通过当我访问myNewFace
在getView()
它问我让它static
方式的代码,当我让static
这样
static Typeface myNewFace = Typeface.createFromAsset(getAssets(),"fonts/bediz__.ttf");
的它给了我下面的错误
Cannot make a static reference to the non-static method getAssets() from the type ContextWrapper
我不知道该怎么做,我做这项工作前几次,但现在我不知道为什么我没有工作。
由于这是一个静态初始值设定项,所以没有'context'对象可以使用。 – CommonsWare
非常感谢你,它的工作。我会在7分钟后接受你的回答 –
@ user1420026很高兴知道它对你有用。如果你愿意,你也可以放心。 – Akram