如何更改列表视图文本颜色? [英] How to change the list view text color?

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

问题描述

有人可以帮我改变列表视图的文本颜色,而无需使用任何基本适配器。我已经使用android.R.layout.simple_list_item_single_choice显示选项按钮,但默认情况下,列表视图中的文本以白色为主色调的显示,我需要将其更改为黑色。有什么办法来改变文字为黑色,而无需使用自定义适配器。我已经粘贴了code这是我用来创建选项按钮列表视图。

 的ListView lvCheckBox =(ListView控件)findViewById(R.id.lvCheckBox);
            节省=(ImageView的)findViewById(R.id.button1);
            lvCheckBox.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            lvCheckBox.setAdapter(新ArrayAdapter<串GT;(这一点,android.R.layout.simple_list_item_single_choice,价值观));


解决方案

只要改变ListView项的默认布局

而不是:

 适配器=新ArrayAdapter<串GT;(这一点,android.R.layout.simple_listview_item,清​​单);

使用

 适配器=新ArrayAdapter<串GT;(这一点,R.layout.customLayout,清单);

和customLayout.xml:

 <?XML版本=1.0编码=UTF-8&GT?;
< TextView中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / listTextView
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字颜色=@彩色/黑白
    机器人:TEXTSIZE =20dp/>

Can somebody please help me to change the text color of list view without using any base adapter. I have used android.R.layout.simple_list_item_single_choice for displaying option button, But by default the text inside the list view is displaying in white color i need to change it to black color. Is there any way to change the text to black without using custom adapter. I have pasted the code which i used to create list view with option button.

  ListView lvCheckBox = (ListView)findViewById(R.id.lvCheckBox);
            save = (ImageView)findViewById(R.id.button1);
            lvCheckBox.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            lvCheckBox.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_single_choice, values));

解决方案

Just change the default layout of the ListView item

Instead of :

adapter = new ArrayAdapter<String>(this, android.R.layout.simple_listview_item, list);

use

adapter = new ArrayAdapter<String>(this, R.layout.customLayout, list);

and customLayout.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/black"
    android:textSize="20dp" />

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

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