如何实现在Android的自定义字体 [英] How to implement custom font in android

查看:220
本文介绍了如何实现在Android的自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现使用自定义数组adpter自定义列表视图。在每行中,有一个文本图和图像。我想添加自定义字体阿拉伯语的文本视图。谁能帮助我加载自定义字体。感谢您事先的任何帮助。

下面是MyViewHolder的code,其中我创建文本视图对象:

 公共静态类MyViewHolder {
    TextView的textViewArabic;
    ImageView的imgView;    公共MyViewHolder(视图V,上下文的背景下){
        // TODO自动生成构造函数存根
        textViewArabic =(TextView中)v.findViewById(R.id.tvArabic);
        imgView =(ImageView的)v.findViewById(R.id.imgView);
    }
}


解决方案

下载TruTypeFace字体(.ttf),并将其放置在资源文件夹。添加以下code从该字体设置为像下面的code文本视图资产得到的字体。

 公共静态类MyViewHolder {
  TextView的textViewArabic;
  ImageView的imgView;
  面对字样;  公共MyViewHolder(视图V,上下文的背景下){
   // TODO自动生成构造函数存根
   textViewArabic =(TextView中)v.findViewById(R.id.tvArabic);
   imgView =(ImageView的)v.findViewById(R.id.imgView);
   FACE = Typeface.createFromAsset(context.getAssets()
                    字体/ _PDMS_Saleem_QuranFont.ttf);
   textViewArabic.setTypeface(面);
  }
 }

I am implementing a custom listview using custom array adpter. In each row, there is a text view and a image. I want to add custom font for arabic on the text view. can anyone help me load custom font. Thanks in advance for any help.

Here is the code of MyViewHolder where i am creating the text view object :

public static class MyViewHolder {
    TextView textViewArabic;
    ImageView imgView;

    public MyViewHolder(View v, Context context) {
        // TODO Auto-generated constructor stub
        textViewArabic = (TextView) v.findViewById(R.id.tvArabic);
        imgView = (ImageView) v.findViewById(R.id.imgView);
    }
}

解决方案

Download a TruTypeFace font (.ttf) and place it in asset folder. Add following code to get that font from assets set that font to your text view like the code below.

public static class MyViewHolder {
  TextView textViewArabic;
  ImageView imgView;
  Typeface face;

  public MyViewHolder(View v, Context context) {
   // TODO Auto-generated constructor stub
   textViewArabic = (TextView) v.findViewById(R.id.tvArabic);
   imgView = (ImageView) v.findViewById(R.id.imgView);
   face = Typeface.createFromAsset(context.getAssets(),
                    "fonts/_PDMS_Saleem_QuranFont.ttf");
   textViewArabic.setTypeface(face);
  }
 }

这篇关于如何实现在Android的自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆