更改ListView的文本颜色 [英] Change ListView's textcolor

查看:191
本文介绍了更改ListView的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变文本的颜色的ListView 但我不能找到如何做到这一点..<

  listViewObject =(ListView控件)findViewById(R.id.chathlist);
    ArrayList的<字符串> chatHistory =新的ArrayList<字符串>();
    chatHistory.add(消息1);
    chatHistory.add(消息2);
    chatHistory.add(消息3);
    chatHistory.add(消息4);
    chatHistory.add(消息5);
    chatHistory.add(消息6);
    chatHistory.add(消息7);
    ArrayAdapter AA =新的ArrayAdapter<字符串>(getApplicationContext()
    android.R.layout.simple_list_item_1,chatHistory);
    listViewObject.setAdapter(AA);
    listViewObject.invalidate();
 

我已经尝试了很多方法,但我不能改变颜色。这可能是简单的事情,但我打这一点。

我的XML文件是

 < RelativeLayout的机器人:ID =@ + ID / chat_history_container
            机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT>
            < ListView控件的android:paddingTop =15dip机器人:paddingBottom会=15dip
                机器人:layout_width =FILL_PARENT机器人:以下属性来=15dip
                机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / chathlist
                机器人:layout_gravity =center_horizo​​ntal
                机器人:layout_centerInParent =真正的机器人:paddingRight =15dip
                 机器人:文字颜色=#FF0000机器人:listSelector =@可绘制/ gradient_box>
            < / ListView控件>
  < / RelativeLayout的>
 

解决方案

这些检查的详细信息:

<一个href="http://www.anddev.org/view-layout-resource-problems-f27/changing-listview-text-color-t14527.html">http://www.anddev.org/view-layout-resource-problems-f27/changing-listview-text-color-t14527.html

<一个href="http://stackoverflow.com/questions/2354176/changing-text-color-of-list-view-in-android">Changing列表视图中的Andr​​oid 文字颜色

更改的ListView文字颜色

请一个布局列表项,并绑定了一个ListAdapter。一个自定义列表视图的一个例子来看看这个网站:<一href="http://p-xr.com/android-tutorial-how-to-parseread-xml-data-into-android-listview/">http://p-xr.com/android-tutorial-how-to-parseread-xml-data-into-android-listview/. (还有一个Eclipse项目的帖子底部)

I am trying to change the text color of the ListView but I cant find how to do that..<

    listViewObject= (ListView) findViewById(R.id.chathlist);        
    ArrayList<String> chatHistory = new ArrayList<String>();
    chatHistory.add("Msg 1");
    chatHistory.add("Msg 2");
    chatHistory.add("Msg 3");
    chatHistory.add("Msg 4");
    chatHistory.add("Msg 5");
    chatHistory.add("Msg 6");
    chatHistory.add("Msg 7");
    ArrayAdapter aa=new ArrayAdapter<String>(getApplicationContext(),
    android.R.layout.simple_list_item_1, chatHistory);
    listViewObject.setAdapter(aa);
    listViewObject.invalidate();

I have tried many ways but I can't change the color. It maybe a simple thing but I'm fighting with this.

My XML file is

  <RelativeLayout android:id="@+id/chat_history_container"
            android:layout_width="fill_parent" android:layout_height="wrap_content">
            <ListView android:paddingTop="15dip" android:paddingBottom="15dip"
                android:layout_width="fill_parent" android:paddingLeft="15dip"
                android:layout_height="wrap_content" android:id="@+id/chathlist"
                android:layout_gravity="center_horizontal"
                android:layout_centerInParent="true" android:paddingRight="15dip"
                 android:textColor="#FF0000"  android:listSelector="@drawable/gradient_box" >
            </ListView>
  </RelativeLayout>

解决方案

Check these for more info:

http://www.anddev.org/view-layout-resource-problems-f27/changing-listview-text-color-t14527.html

Changing text color of list view in android

Change Text Color in ListView

Make a layout for your List items and bind that to a ListAdapter. See this site for an example of a custom listview: http://p-xr.com/android-tutorial-how-to-parseread-xml-data-into-android-listview/. ( There is an Eclipse project to the bottom of the post )

这篇关于更改ListView的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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