-1

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

在 xml 中......

4

4 回答 4

0

First add your font file in your assets folder and use this code

Typeface arial = Typeface.createFromAsset(getAssets(), "fonts/arial.ttf");
name_txt.setTypeface(arial);
于 2013-01-21T07:19:19.500 回答
0

使用自定义列表 -

要更改为不同的内置字体,请在 List Item XML 中使用 android:typeface

或 ArrayAdopter 的 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);

.....
}

_ }

于 2013-01-21T07:51:17.137 回答
0
Typeface typeBold = Typeface.createFromAsset(getAssets(),"fonts/helveticabold.ttf");
Typeface typeNormal = Typeface.createFromAsset(getAssets(), "fonts/helvetica.ttf");

更多信息请尝试以下链接

示例1

示例2

于 2013-01-21T07:08:10.943 回答
0
In android listview i want to change the font in my own style.

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

首先在适配器的构造函数中初始化字体可能如下

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

然后在getView()

@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;
    }
于 2013-01-21T07:11:29.847 回答