如何改变字体和颜色在这个列表视图 [英] How to change font type and color in this listview

查看:231
本文介绍了如何改变字体和颜色在这个列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个字符串数组:数组1 数组2

我怎样才能更改字体类型?结果
我怎样才能改变颜色的数组(例如第一和第五元素)的一些元素?结果
我的字体类型为RAW / price.ttf。

  ListView控件ListView1的=(的ListView)findViewById(R.id.listView1);清单<地图<字符串,字符串>>数据=新的ArrayList<地图<字符串,字符串>>();
    的for(int i = 0; I< array2.length;我++){
        地图<字符串,字符串>基准=新的HashMap<字符串,字符串>(2);
        datum.put(称号,数​​组1 [I]);
        ([I])副标题,将String.valueOf(数组2)datum.put;
        data.add(基准面);
    }SimpleAdapter适配器3 =新SimpleAdapter(这一点,数据,
                                   android.R.layout.simple_list_item_2,
                                   新的String [] {标题,副标题},
                                   新的INT [] {android.R.id.text1,
                                              android.R.id.text2});
listView1.setAdapter(适配器3);

下面是我的XML

 < ListView控件
        机器人:ID =@ + ID / ListView1的
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:scrollingCache =假>
    < /&的ListView GT;


解决方案

创建CustomAdapter和您有getView()所以,如果你想改变列表视图的字体使用:

有关更改字体:

 最终字样字体= Typeface.createFromAsset(assetManagerprice.TTF);
    listview1.setTypeface(字体);

&安培;颜色:

  listview1.setTextColor(Color.BLACK);

I have two string arrays: array1 and array2.

How can I change the font type?
How can I change the color for some element of the array (for example the first and the fifth element)?
My font type is in raw/price.ttf.

ListView listView1=(ListView) findViewById(R.id.listView1);

List<Map<String, String>> data = new ArrayList<Map<String, String>>();
    for (int i=0; i<array2.length; i++) {
        Map<String, String> datum = new HashMap<String, String>(2);
        datum.put("title", array1[i]);
        datum.put("subtitle", String.valueOf(array2[i]));
        data.add(datum);
    }

SimpleAdapter adapter3 = new SimpleAdapter(this, data,
                                   android.R.layout.simple_list_item_2,
                                   new String[] {"title", "subtitle"},
                                   new int[] {android.R.id.text1,
                                              android.R.id.text2});
listView1.setAdapter(adapter3);

Here is my xml

<ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" 
        android:scrollingCache="false">
    </ListView>

解决方案

Create a CustomAdapter and in that you have the getView() so there if you want to change the listview font use this :

For changing font :

final Typeface font = Typeface.createFromAsset(assetManager, "price.TTF");
    listview1.setTypeface(font);

& Color:

    listview1.setTextColor(Color.BLACK);

这篇关于如何改变字体和颜色在这个列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆