无法更改以编程方式查看背景颜色

时间:2015-05-10 08:24:32

标签: android

我是一个Android新手所以请原谅我......

这是我的代码:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;

    if (convertView == null) {
        viewHolder = new ViewHolder();
        convertView = LayoutInflater.from(context).inflate(R.layout.adapter_who_row, null);
        viewHolder.nameTextView = (TextView) convertView.findViewById(R.id.text);
        viewHolder.companyTextView = (TextView) convertView.findViewById(R.id.whoRowCompany);
        viewHolder.dotView = convertView.findViewById(R.id.whoRowDot);

        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    String textToShow = dataArray.get(position);
    viewHolder.nameTextView.setText(textToShow);
    viewHolder.dotView.setBackgroundColor(getResources().getColor(R.color.red));
    viewHolder.companyTextView.setText("Test");

    return convertView;
}


class ViewHolder {
    TextView nameTextView;
    TextView companyTextView;
    View dotView;
}

dotView没有改变它的颜色...... 但是,这两个textVies确实改变了他们的文本。

它可能是什么?

编辑: xml持有两个editTexts和一个View。

下面是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content" android:layout_centerVertical="true">


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.85"
            android:layout_gravity="center"
            android:gravity="center">

            <View
                android:id="@+id/whoRowDot"
                android:layout_width="40px"
                android:layout_height="40px"
                android:backgroundTint="@color/noteColor">

            </View>
            <!--android:background="@drawable/round_button"-->


        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical"
            android:background="@color/clear"
            android:layout_weight="0.15">

            <TextView
                android:id="@+id/text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="0dp"
                android:text="User Name"
                android:fontFamily="Roboto-Light"
                android:background="@color/clear"/>

            <TextView
                android:id="@+id/whoRowCompany"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="15dp"
                android:text="Company"
                android:textColor="@color/lightGrey"
                android:background="@color/clear"/>

        </LinearLayout>


    </LinearLayout>


</LinearLayout>

由于

1 个答案:

答案 0 :(得分:1)

从xml视图中删除此行并尝试:

android:backgroundTint="@color/noteColor"