android spinner change font typeface

前端 未结 5 2063
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 14:23

i\'m going to change text typeface to arialbold in my spinner how i\'m going to do so. Below is my code :-

ArrayAdapter genderAdap = Arra         


        
5条回答
  •  离开以前
    2020-12-06 15:08

    Here is how you can do it, set your adapter as below:

    mMsgAdap =new ArrayAdapter(getApplicationContext(), R.layout.spinner_item_list, mCategories)
                    {
    
                        public View getView(int position, View convertView, ViewGroup parent) 
                            {
                                View v = super.getView(position, convertView, parent);
                                ((TextView) v).setTypeface(StaticUtils.sTypeFace(getApplicationContext()));//Typeface for normal view
    
                                return v;
                            }
                        public View getDropDownView(int position, View convertView, ViewGroup parent) 
                            {
                                View v = super.getDropDownView(position, convertView, parent);
                                ((TextView) v).setTypeface(StaticUtils.sTypeFace(getApplicationContext()));//Typeface for dropdown view
                                ((TextView) v).setBackgroundColor(Color.parseColor("#BBfef3da"));
                                return v;
                            }
                    };
            mMsgAdap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mMsgSpnr.setAdapter(mMsgAdap);
            mMsgSpnr.setSelection(0);
    

    and the typeface method I have taken statically inside StaticUtils class that I created is

    public static Typeface sTypeFace(Context mCnxt) {
        Typeface mtypeface = Typeface.createFromAsset(mCnxt.getAssets(),
                "fonts/forte-mt-1361539051.ttf");
        return mtypeface;
    }
    

提交回复
热议问题