简体   繁体   中英

How to set custom font for string array in grid view

I seem to not be able to figure out how to setup custom font for a string array.

String quizname[] = {"Cricket", "Football", "Tennis", "Golf", "Rugby", `"Hardcore",};`

I know how to set custom font for a text view like so but not sure how for a string in a grid view:

    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);
    }

You can set font in recyclerView items in onBindViewHolder

Example:

class Holder extends RecyclerView.ViewHolder {

        TextView t;

        public Holder(View itemView) {
            super(itemView);
            t = itemView.findViewById(R.id.text);
        }
    }

and in your onBindViewHolder

@Override
public void onBindViewHolder(@NonNull Holder holder, int position) {
      holder.t.setTypeface(custom_font);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM