java - 如何在网格视图中为字符串数组设置自定义字体
问题描述
我似乎无法弄清楚如何为字符串数组设置自定义字体。
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);
}
推荐阅读
- amazon-web-services - 无法从 API Gateway 向 FIFO SQS 发送消息
- awk - 修剪 ps x 以删除进程名称之前的路径
- python - 如何安装 requests、beautifulsoup4、bs4 模块
- java - 如何设置x按钮一次清除文本,第二次关闭SearchView Android?
- maven - Browserstack 自动化 Maven 插件不工作
- c# - OpenXml (.net):SimpleField 未格式化
- solr - SOLR CLOUD - 上传 LTR 功能
- c# - 使用 MouseMove 滚动 TreeView
- python - 让 tox/pip 识别使用 Jenkins 部署的诗歌包的私有工件
- k-means - k表示算法如何实现颜色压缩