4
我無法在列表視圖上設置字體,字體僅適用於textviews。有什麼方法可以輕鬆設置自定義字體嗎?謝謝。如何在我的listview上設置自定義字體?
我無法在列表視圖上設置字體,字體僅適用於textviews。有什麼方法可以輕鬆設置自定義字體嗎?謝謝。如何在我的listview上設置自定義字體?
你可以爲你的列表視圖的適配器,並設置字體類型上TextView的存在。
這裏是一個適配器的夾子(其在C#中,但它並不比Java的太不一樣了):
class ParcelRecordContactAdapter : ArrayAdapter<ParcelRecordContact>
{
List<ParcelRecordContact> contacts;
public ParcelRecordContactAdapter(Context context, int textViewResourceId, List<ParcelRecordContact> contacts)
: base(context, textViewResourceId, contacts)
{
this.contacts = contacts;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater li = (LayoutInflater)this.Context.GetSystemService(Context.LayoutInflaterService);
v = li.Inflate(Resource.Layout.ListItem_SingleLine, null);
}
ParcelRecordContact contact = contacts[position];
if (contact != null)
{
/**********************************************************
* change font on tv here
**********************************************************/
TextView tv = (TextView)v.FindViewById(Resource.Id.tv_single_line_list_item_1);
if (tv != null)
{
tv.Text = "android is fu.... n"
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/DroidSansFallback.ttf");
tv.setTypeface(tf);
}
}
return v;
}
}
這個問題實際上是重複的。看看這裏的答案(在Java中,仇恨):http://stackoverflow.com/questions/7361135/how-to-change-color-and-font-on-listview – samosaris
設置自定義字體textviews在您的列表視圖 –
使用自定義列表適配器,並設置字體在「getView」覆蓋。 http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/ – Kuffs
@Kuffs所以你說,當我重寫getView方法我也插入一個字體改變字體? – Eulante