码迷,mamicode.com
首页 > 移动开发 > 详细

修改 android ListView 字体大小及颜色

时间:2017-01-12 18:24:40      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:list   void   添加   images   XML   创建   schema   网上   ext   

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 }


效果如图:

技术分享

 

修改 android ListView 字体大小及颜色

标签:list   void   添加   images   XML   创建   schema   网上   ext   

原文地址:http://www.cnblogs.com/-sev-/p/6279234.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!