-1

I am new in android. In android listview i want to change the font in my own style. Please reply. thanks in advance step by step how to change the font in list view.

in xml....

santhosh
  • 1
  • 1
  • 1

4 Answers4

0
Typeface typeBold = Typeface.createFromAsset(getAssets(),"fonts/helveticabold.ttf");
Typeface typeNormal = Typeface.createFromAsset(getAssets(), "fonts/helvetica.ttf");

More information try the following links

example1

example2

Community
  • 1
  • 1
Janmejoy
  • 2,721
  • 1
  • 20
  • 38
0
In android listview i want to change the font in my own style.

By this, I suppose you want to change the font in the child view that is being displayed in the list. For that you need to set the typeface of the TextView inside the getView() as follows

First initialize the font in the constructor of the adapter maybe as follows

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

and then in the 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;
    }
Antrromet
  • 15,294
  • 10
  • 60
  • 75
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);
MuraliGanesan
  • 3,233
  • 2
  • 16
  • 22
0

Use Customized List -

To change to a different built-in font, use android:typeface in List Item XML

or setTypeface() in getView of ArrayAdopter.

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

.....
}

_ }

Jambaaz
  • 2,788
  • 1
  • 19
  • 30