custom font in android ListView

后端 未结 8 706
清歌不尽
清歌不尽 2020-11-29 06:15

I\'m using a custom font throughout my application (which, incidentally, I\'ve frustratingly found out that you have to apply programmatically by hand to EVERY control!), an

8条回答
  •  悲哀的现实
    2020-11-29 06:47

    You can Set base Adapter like follow Steps May be help you

    Define your Base Adapter

    public class LessonAdapter extends BaseAdapter {
    
        private Context mContext;
    
        public LessonAdapter(Context mContext, ArrayList titles) {
            super();
            this.mContext = mContext;
        }
    
        public int getCount() {
            // TODO Auto-generated method stub
            if (titles!=null)
                return titles.size();
            else
                return 0;
        }
    
        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return null;
        }
    
        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return 0;
        }
    
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View v = convertView;
            try
            {
                if (v == null) {
                    v = inflater.inflate(R.layout.lesson_item, null);
                }
                    TextView title = (TextView) v.findViewById(R.id.title);
    
                    Typeface tf = Typeface.createFromAsset(getAssets(),
                            "fonts/Rabiat_3.ttf");
                    title.setTypeface(tf);
    
                    title.setText(titles.get(position).toString());     
    
            }
            catch (Exception e) {
                Log.d("searchTest", e.getMessage());
            }
    
            return v;
        }
    
    }
    

    by TypeFace Method you can set your font by add folder 'Fonts' in Assets then add your font in 'Fonts' Folder

    then to set your adapter

    adapter = new LessonAdapter(LessonsTitle.this, titles);
        setListAdapter(adapter);
    

提交回复
热议问题