Android Listview字体样式

Android Listview字体样式,android,android-listview,custom-font,Android,Android Listview,Custom Font,我是android新手。在android listview中,我想以自己的风格更改字体。请回复。提前感谢如何在列表视图中更改字体 在xml中。。。。 更多信息请尝试以下链接 这样,我想您需要更改列表中显示的子视图中的字体。为此,您需要在getView()中设置TextView的字体,如下所示 首先在适配器的构造函数中初始化字体,如下所示 private Typeface typeFace; public MyContructor(Context context) {

我是android新手。在android listview中,我想以自己的风格更改字体。请回复。提前感谢如何在列表视图中更改字体

在xml中。。。。

更多信息请尝试以下链接

这样,我想您需要更改列表中显示的子视图中的字体。为此,您需要在
getView()
中设置
TextView
字体,如下所示

首先在适配器的构造函数中初始化字体,如下所示

private Typeface typeFace;
public MyContructor(Context context)
    {
        super(context);
        mInflater = LayoutInflater.from(mContext);
        typeFace=Typeface.createFromAsset(mContext.getAssets(), "Fonts/GrinchedRegular.ttf"));
    }
然后在
getView()中


首先在资产文件夹中添加字体文件并使用此代码

Typeface arial = Typeface.createFromAsset(getAssets(), "fonts/arial.ttf");
name_txt.setTypeface(arial);
使用自定义列表-

要更改为其他内置字体,请在列表项XML中使用android:typeface

或ArrayDopter的getView中的setTypeface()

public class CustomeArrayAdopter extends ArrayAdapter<String> {
int res;
Typeface tf;

public CustomeArrayAdopter(Context ctx, int resource,  
    List<String> items) {

super(ctx, res,items);
res=resource;
tf=Typeface.createFromAsset(ctx.getAssets(),"font/Arial.ttf");
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
//Apply new TypeFace here
TextView item_text=(TextView)findViewById(R.id.listItemtv);
item_text.setTypeface(tf);

.....
}
public类customarrayadopter扩展了ArrayAdapter{
国际关系;
字体tf;
公共Customerrayadopter(上下文ctx、int资源、,
(列表项目){
超级(ctx、res、项目);
res=资源;
tf=Typeface.createFromAsset(ctx.getAssets(),“font/Arial.ttf”);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//在此应用新字体
TextView项_text=(TextView)findViewById(R.id.listItemtv);
项目文本设置字体(tf);
.....
}

_}

Santosh这是一个重复的问题,看看这个问题,你的答案我上面粘贴的所有链接都是你问题的重复。您不可能从XML实现这一点。
@Override
    public View getView(final int position, View convertView, final ViewGroup parent)
    {
        if (convertView == null)
        {
            convertView = mInflater.inflate(R.layout.sample, null);
        }
        myText = (TextView) convertView.findViewById(R.id.my_text);
        myText.setTypeface(typeFace);
        return convertView;
    }
Typeface arial = Typeface.createFromAsset(getAssets(), "fonts/arial.ttf");
name_txt.setTypeface(arial);
public class CustomeArrayAdopter extends ArrayAdapter<String> {
int res;
Typeface tf;

public CustomeArrayAdopter(Context ctx, int resource,  
    List<String> items) {

super(ctx, res,items);
res=resource;
tf=Typeface.createFromAsset(ctx.getAssets(),"font/Arial.ttf");
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
//Apply new TypeFace here
TextView item_text=(TextView)findViewById(R.id.listItemtv);
item_text.setTypeface(tf);

.....
}