Изменить цвет текста флажка в виде списка - PullRequest
0 голосов
/ 14 апреля 2020

Итак, у меня есть список флажков в массиве списков, заполненный различным текстом и настраиваемой галочкой, которая эффективно отображается, когда я нажимаю на указанный элемент c. Тем не менее, я не могу изменить цвет текста текста в проверяемом элементе. Я хочу изменить его на тот же цвет, что и галочка. Когда я нажимаю на элемент и когда цвет текста устанавливается на приведенный ниже код textColor, текст становится розовым! это не тот цвет, который я хочу. Кажется, это цвет по умолчанию. Мой вопрос тогда, как я могу изменить textColor определенного флажка, который я проверил, который встроен в просмотр списка? Я искал на этом сайте и других, но я не мог найти ответ, который мог бы помочь мне.

цвет текста

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:textColor="@color/purple_color" />
</selector>

и фиолетовая галочка:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/transparent" android:state_checked="false"/>
    <item android:drawable="@drawable/ic_check_black_24dp" android:state_checked="true"/>
</selector>

и представление списка в упражнении:

<ListView
            android:id="@+id/myList"
            android:paddingTop="12dp"
            android:layout_marginLeft="44dp"
            android:layout_marginRight="44dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

и отдельный список item:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <CheckBox
        android:id="@+id/orientation_type"
        android:layout_width="fill_parent"
        android:layout_height="44dp"
        android:gravity="left|center_vertical"
        android:textColor="@drawable/check_box_text_color_purple"
        android:textSize="17dp"
        android:layoutDirection="rtl"
        android:button="@drawable/check_purple" />

</LinearLayout>

и адаптер массива:

public class orientation_adapter extends ArrayAdapter<orientation_item> {

    private Context mContext;
    int mResource;

    public orientation_adapter(@NonNull Context context, int resource, @NonNull ArrayList<orientation_item> objects) {
        super(context, resource, objects);
        this.mContext = context;
        this.mResource = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        String orientation = getItem(position).getOrientation();

        gender_item user_orientation = new gender_item(orientation);

        LayoutInflater inflator = LayoutInflater.from(mContext);
        convertView = inflator.inflate(mResource, parent, false);

        //TextView orientation_type = (TextView) convertView.findViewById(R.id.orientation_type);
        CheckBox orientation_type = (CheckBox) convertView.findViewById(R.id.orientation_type);

        orientation_type.setText(orientation);

        return convertView;

    }

}

и основной вид деятельности:

ArrayList<orientation_item> list = new ArrayList<>();

 //items created and added here

 adapter = new orientation_adapter(ChooseOrientation.this, R.layout.orientation_unit, list);

        myList.setAdapter(adapter);

1 Ответ

0 голосов
/ 14 апреля 2020

В итоге я применил это к полю android: textColor в отдельном компоненте xml списка. Это решило проблему, но похоже на то, что я делал раньше. Android, кажется, реагирует лучше, когда вы используете реальные цветовые коды вместо ссылок на цвета.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false" android:color="#000000"/>
    <item android:state_checked="true" android:color="#FF6C63FF"/> <!-- checked -->
    <item android:color="#ffffff"/> <!-- anything else -->
</selector>
...