安卓:更改文本颜色的ListView的singleChoice [英] Android: Change text color in ListView for singleChoice

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

问题描述

我有一个列表视图设置为使用singleChoice。所有我想要做的就是改变默认的背景颜色为白色,文本颜色为黑色。我无法弄清楚如何做到这一点。这里是我的XML布局:

I have a listview set to use singleChoice. All I want to do is change the default background color to white and the text color to black. I cannot figure out how to do this. Here is my xml layout:

<ListView
    android:id="@+id/lvSpeeds"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@id/llToolbar"
    android:layout_below="@id/rgSpeedUnits"
    android:textColor="@android:color/black"
    android:choiceMode="singleChoice"
    android:background="#ffffff"
    android:cacheColorHint="#00ffffff"
    android:clickable="true"
    android:divider="#ff000000"
    android:dividerHeight="1dp"
    android:focusable="true"
    android:scrollingCache="true" />

编辑:我要指出,我想改变code这只能使用XML布局文件,而不是。我已经知道如何在code做到这一点。使用比android.R.layout.simple_list_item_single_choice迫使你实现一个适配器,绑定,多写code,等其他自定义布局。从浏览了很多帖子,似乎没有可以使用纯XML来改变文字颜色。事实上,它似乎并不可能在行上改变任何东西作为底层布局android.R.layout.simple_list_item_single_choice无法访问。

I should have pointed out that I want to change this only using xml layout files and NOT in code. I already know how to do this in code. Using a custom layout other than android.R.layout.simple_list_item_single_choice forces you to implement an adapter, bind, write more code, and so on. From viewing a lot more posts, it does not appear possible to change the text color using only xml. In fact, it doesn't seem possible to change anything on a row as the underlying layout android.R.layout.simple_list_item_single_choice is not accessible.

推荐答案

尝试这样的:

插入到此code适配器在getview马托:

insert to this code in adapter in getview mathod:

LinearLayout mRowLayout = (LinearLayout) vi
                    .findViewById(R.id.list_item_layout);
            final TextView title = (TextView) vi
                    .findViewById(R.id.list_item);

            title.setText(Massage[position]);

            mRowLayout.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {


                                    title.setTextColor(Color.RED);

                            });

在这里LIST_ITEM code:

here list_item code:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list_item_layout"
android:orientation="vertical" >


<RelativeLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/row_single"
                android:layout_margin="5dp">


<TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:textColor="@android:color/black"
        android:padding="10dp"
        android:textSize="16sp"

        android:layout_toLeftOf="@+id/arrow"
        android:id="@+id/list_item"/>
</RelativeLayout>
</LinearLayout>

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

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