[英]How to set custom font for string array in grid view
我似乎無法弄清楚如何為字符串數組設置自定義字體。
String quizname[] = {"Cricket", "Football", "Tennis", "Golf", "Rugby", `"Hardcore",};`
我知道如何為這樣的文本視圖設置自定義字體,但不確定如何為網格視圖中的字符串設置:
Typeface custom_font = Typeface.createFromAsset(getAssets(), "slant.TTF");
prefs = getSharedPreferences("appPurchase", 0);
editor = prefs.edit();
textView.setTypeface(custom_font);
textView.setTextColor(getResources().getColor(R.color.gold));
custGridList = new ArrayList<>();
for (int i = 0; i < quizname.length; i++) {
CustGridList list = new CustGridList();
list.setQuizImg(imgs[i]);
list.setQuizName(quizname[i]);
custGridList.add(list);
}
您可以在onBindViewHolder
recyclerView項目中設置字體
例:
class Holder extends RecyclerView.ViewHolder {
TextView t;
public Holder(View itemView) {
super(itemView);
t = itemView.findViewById(R.id.text);
}
}
並在您的onBindViewHolder
@Override
public void onBindViewHolder(@NonNull Holder holder, int position) {
holder.t.setTypeface(custom_font);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.