【问题标题】:Android Listview font styleAndroid Listview 字体样式
【发布时间】:2013-01-21 06:59:19
【问题描述】:

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

在xml中......

【问题讨论】:

标签: android android-listview custom-font


【解决方案1】:
Typeface typeBold = Typeface.createFromAsset(getAssets(),"fonts/helveticabold.ttf");
Typeface typeNormal = Typeface.createFromAsset(getAssets(), "fonts/helvetica.ttf");

更多信息请尝试以下链接

example1

example2

【讨论】:

    【解决方案2】:
    In android listview i want to change the font in my own style.
    

    由此,我想您想更改列表中显示的子视图中的字体。为此,您需要在getView() 内设置TextViewtypeface,如下所示

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

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

    【讨论】:

      【解决方案3】:

      首先将您的字体文件添加到您的资产文件夹中并使用此代码

      Typeface arial = Typeface.createFromAsset(getAssets(), "fonts/arial.ttf");
      name_txt.setTypeface(arial);
      

      【讨论】:

        【解决方案4】:

        使用自定义列表 -

        要更改为不同的内置字体,请在列表项 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);
        
        .....
        }
        

        _ }

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-08-01
          • 2012-11-26
          • 2011-03-07
          • 1970-01-01
          相关资源
          最近更新 更多