Search code examples
androidlistviewfontsexpandable

how to use external font in expandable listview?? (Android Studio)


hi i'm trying to change the font of the parent text (the subjects) in my expandable list view by using an external font. i've already placed my font in assets>fonts. context is red in my code here

subjects_adapter.java

    public View getGroupView(int parent, boolean isExpanded, View convertView, ViewGroup parentView) {
    String group_title = (String) getGroup(parent);
    if (convertView == null){
        LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.parent_layout, parentView, false);
    }
    TextView parent_text_view = (TextView) convertView.findViewById(R.id.parent_text);
    Typeface regular = Typeface.createFromAsset(context.getAssets(), "PLAYBILL.ttf");
    parent_text_view.setTypeface(regular, Typeface.NORMAL);
    parent_text_view.setText(group_title);

    return convertView;
}

Solution

  •     Typeface regular = Typeface.createFromAsset(ctx.getAssets(),
                "fontname.ttf");
        parent_text_view.setTypeface(regular, Typeface.NORMAL);
    

    Place in your groupview after initialization of parent_text_view

    Hope it works fine