Android系统。我怎样才能改变上点击一个ListView文本颜色?文本、颜色、系统、Android

由网友(戒不掉爱你)分享简介:我改变这个code中的颜色,但颜色的变化,只有当我从应用程序退出并重新运行。如何解决即时改变颜色? 适配器2 =新ArrayAdapter<串GT;(getApplicationContext()            android.R.layout.simple_list_item_1,列表){...

我改变这个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/><! - 默认 - > 
android listview item字体,Android ListView 点击Item的时候,改变文字颜色和背景色

并将其设置为机器人:文字颜色=@色/ 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.

阅读全文

相关推荐

最新文章