我正在尝试从资产文件夹中为以下代码设置字体
int[] listeitems = new int[] { R.id.title };
Typeface childFont = Typeface.createFromAsset(getActivity().getAssets(),"fonts/Roboto-Thin.ttf");
mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item,
null,
new String[] { android.provider.MediaStore.Audio.Media.TITLE,
// android.provider.MediaStore.Audio.Albums.ALBUM,
}, listeitems, 0);
try {
setListAdapter(mAdapter);
}
如何为上面的代码设置SimpleCursorAdapter的字体。
答案 0 :(得分:0)
试试这个,
创建FontStyle类
import android.content.Context;
import android.graphics.Typeface;
public class FontStyle {
public static Typeface OswaldRegular(Context context) {
Typeface tf = null;
try {
tf = Typeface.createFromAsset(context.getAssets(), "Oswald-Regular.ttf");
} catch (Exception e) {
e.printStackTrace();
}
return tf;
}
}
设置以下代码,将字体样式设置为您的活动:
TextView txtHeader = (TextView) findViewById(R.id.txtHeader);
txtHeader.setTypeface(FontStyle.OswaldRegular(MainActivity.this));
答案 1 :(得分:0)
进入SimpleCursorAdapter类 字体childFont = Typeface.createFromAsset(getActivity()。getAssets()," fonts / Roboto-Thin.ttf"); textfield.setTypeface(TF,Typeface.BOLD);
答案 2 :(得分:0)
请看这个
SimpleCursorAdapter.ViewBinder binding = new SimpleCursorAdapter.ViewBinder() {
boolean SetViewValue(View view, Cursor cursor, int columnIndex) {
TextView tv1=(TextView)view.findViewById(R.id.textView1);
TextView tv2=(TextView)view.findViewById(R.id.textView2);
TextView tv3=(TextView)view.findViewById(R.id.textView3);
//Setting typeface here
return true;
}
});
adapter.setViewBinder(binding);