如何在ListView中设置文本的颜色

时间:2017-05-10 19:05:24

标签: android listview

这里我在ListView中为值设置了行的颜色。现在我想只设置这个字符串的颜色,没有所有行

ListAdapter adapter = new SimpleAdapter(MainActivity.this, DevicesList,
                    R.layout.list_item, new String[]{"name", "clients", "stan"},
                    new int[]{R.id.name, R.id.clients, enabled}){
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View view = super.getView(position, convertView, parent);
                    TextView v = (TextView) view.findViewById(R.id.enabled);
                    String a = v.getText().toString();

                    if (a == "Aktywny") {
                        view.setBackgroundColor(Color.argb(125,53,104,45));
                    } else if(a == "Nieaktywny") {
                        view.setBackgroundColor(Color.argb(125,175,43,30));
                    } else{
                        view.setBackgroundColor(Color.argb(125,139,140,122));
                    }

                    return view;
                }
            };

1 个答案:

答案 0 :(得分:0)

v.setTextColor(Color.argb(125,175,43,30))