2
我有一個ListView,我想要做的就是更改字體。我已經將我的字體下載到assets/fonts文件夾。更改textview的字體
如果我的理解對不對,我應該重寫適配器..
這裏是我的代碼:
onCreate....
Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/english.ttf");
font1 = Typeface.create(font1, Typeface.BOLD);
TextView customText = (TextView)findViewById(R.id.ListTextView);
customText.setTypeface(font1);
HashMap<String,String> contentItem = new HashMap<String,String>()
{
{
put(NAME_FIELD,"dudi");
}
};
content.add(contentItem);
SimpleAdapter adapter = new SimpleAdapter(this,
content,
R.layout.show_the_list,
new String[]{NAME_FIELD},
new int[]{R.id.ListTextView} );
ListView list1 = (ListView) findViewById(R.id.list);
list1.setAdapter(adapter);
xml文件:
<TextView
android:id="@+id/ListTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dip"
android:textColor="@color/White" >
</TextView>
,如果有人可以告訴我代碼,我需要添加或更改,這將是偉大的! 謝謝。
謝謝你你的答案。我如何使用字體在xml中編寫它?我嘗試了幾個compination,但沒有成功... – user1673206
其實,因爲我看到你作爲一個初學者,所以它複雜的你創建自定義TExtView和添加字體在XML中。因此,最好編寫一個CustomAdapter,並在其中的getView()中將TypeFace設置爲TextView。 – user370305
o.k .. 有任何我可以使用的例子嗎? 謝謝。 – user1673206