修改 android ListView 字体大小及颜色

android中ListView的默认字体有时会满足不了设计的需求,需要设计自己的风格,

一般网上介绍的是新建一个自己的 ListView的适配器MyAdapter,现有另一种方法可避免新建MyAdapter的麻烦。

1、在res/layout/下新建 array_adapter.xml :

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/TextView"
 4     android:layout_width="wrap_content"
 5     android:layout_height="wrap_content"
 6     android:textSize="24sp"
 7     android:padding="10dp" 
 8     android:textColor="#ff000000"   
 9     android:shadowDx="4"
10     android:shadowDy="4"
11     android:shadowRadius="2"
12  />

其中"android:textSize"及"android:textColor"就可以指定字体大小及颜色,当然也可以进行其他的设置如添加阴影等"android:shadowColor"。

 

2、在MainActivity中创建适配器,并将array_adapter.xml与适配器想关联:

 1 private ListView    m_logList=null;
 2 private ArrayAdapter adapter = null;
 3 private ArrayList<String> m_logTexts;
 4 
 5 public void onCreate(Bundle savedInstanceState) {
 6     super.onCreate(savedInstanceState);
 7     // .. .. ..
 8 
 9     m_logList = (ListView)this.findViewById(R.id.listView1);
10     m_logTexts=new ArrayList<String>();
11     m_logTexts.add("Hello World.");
12     m_logTexts.add("11 22 33");
13 
14     // 创建适配器,并把数据交给适配器  
15     adapter = new ArrayAdapter(this,R.layout.array_adapter,m_logTexts);        
16     // 为listView添加适配器  
17     m_logList.setAdapter(adapter);
18     
19 }
20 
21 public void onLog(String str) {
22 
23     while(m_logTexts.size()>15)
24     {
25         m_logTexts.remove(0);
26     }
27     m_logTexts.add(str);
28 
29         //  通知显示
30     adapter.notifyDataSetChanged();
31 }


效果如图:

 

转载于:https://www.cnblogs.com/-sev-/p/6279234.html

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值