以下是我的代码:
我想更改 id 为“name12”的 Textview 的字体。需要帮忙。预先感谢您。
String rid = jObj.getString(TAG_RID);
String name = jObj.getString(TAG_NAME);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_RID, rid);
map.put(TAG_NAME, name);
oslist.add(map);
ListAdapter adapter = new SimpleAdapter(MainActivity.this, oslist,
R.layout.list_v, new String[] { TAG_NAME }, new int[] { R.id.name12});
l1.setAdapter(adapter);
最佳答案
您可以扩展TextView
类并在其中设置字体。
之后你就可以在R.layout.list_v
中使用这个TextView
public class TextViewWithFont extends TextView {
public TextViewWithFont(Context c) {
this(c, null);
}
public TextViewWithFont(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setTypeface(Typeface.createFromAsset(context.getAssets(), "fontname.ttf"));
}
public TextViewWithFont(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
}
关于java - 当textview是listview的一部分时,如何使用SimpleAdapter更改textview的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22223319/