嗨我正在嘗試更改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