Android系统。我怎样才能改变上点击一个ListView文本颜色? [英] Android. How can I change a ListView text color on click?

查看:110
本文介绍了Android系统。我怎样才能改变上点击一个ListView文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我改变这个code中的颜色,但颜色的变化,只有当我从应用程序退出并重新运行。如何解决即时改变颜色?

 适配器2 =新ArrayAdapter<串GT;(getApplicationContext()
            android.R.layout.simple_list_item_1,列表){
        @覆盖
        公共查看getView(INT位置,查看convertView,父母的ViewGroup){
            查看查看= super.getView(位置,convertView,父母);
            TextView的文本=(TextView的)查看
                    .findViewById(android.R.id.text1);
            text.setTextColor(Color.parseColor(彩色));
            返回视图。
        }
    };


解决方案

放入RES /彩色文件夹此文件作为 textselector_list.xml

 <?XML版本=1.0编码=UTF-8&GT?;

 <项目的android:STATE_ pressed =真正的机器人:颜色=#FFFFFFFF/>
<! - pressed - >
<项目的android:state_focused =真正的机器人:颜色=#FFFFFFFF/>
<! - 集中 - >
<项目的android:state_selected =真正的机器人:颜色=#FFFFFFFF/>
<! - 选择 - >
<项目的android:颜色=#FF888888/>
<! - 默认 - >

并将其设置为机器人:文字颜色=@色/ textselector_list的ListView 项目即你的的TextView 按钮

I change the color with this code, but the color changes only when i quit from the application and run it again. How can I resolve to change immediately the color?

adapter2 = new ArrayAdapter<String>(getApplicationContext(),
            android.R.layout.simple_list_item_1, list) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            TextView text = (TextView) view
                    .findViewById(android.R.id.text1);
            text.setTextColor(Color.parseColor(color));
            return view;
        }
    };

解决方案

Put this file in res/color folder as textselector_list.xml

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

<item android:state_pressed="true" android:color="#FFFFFFFF"/>
<!-- pressed -->
<item android:state_focused="true" android:color="#FFFFFFFF"/>
<!-- focused -->
<item android:state_selected="true" android:color="#FFFFFFFF"/>
<!-- selected -->
<item android:color="#FF888888"/>
<!-- default -->

And set this as android:textColor="@color/textselector_list" to the listView item i.e. your TextView or Button.

这篇关于Android系统。我怎样才能改变上点击一个ListView文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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