I can't change the color when the item is pressed Here is my code I have tried many ways but it doesn't seem to work
In the adapter,
binding.apply {
barFilled.apply {
val color = context.getColor(R.color.selector_item_chart)
backgroundTintList = ColorStateList.valueOf(color)
var percentStepCounter: Float =
(item.stepCounter.toFloat() / ConstantNumber.MAX_STEP.toFloat())
if (percentStepCounter >= 1f) percentStepCounter = 1f
val params = layoutParams as ConstraintLayout.LayoutParams
params.matchConstraintPercentHeight = percentStepCounter
requestLayout()
}
textSupporting.text = sdf.parse(item.date)?.let { newSimpleDateFormat.format(it) }
textSupporting.setOnClickListener {
onClickControl.onClick(item)
}
barFilled.setOnClickListener {
onClickControl.onClick(item)
}
}
In item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="42sp"
android:layout_height="212sp"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingHorizontal="4sp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingStart="10sp"
android:paddingEnd="10sp">
<View
android:id="@+id/bar_filled"
android:layout_width="match_parent"
android:layout_height="0sp"
android:background="@drawable/shape_chart_bar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_percent=".5" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/text_supporting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4sp"
android:text="@string/date"
android:textAlignment="center"
android:textSize="12sp" />
</LinearLayout>
và in selector_item.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/light_green" />
<item android:color="@color/dark_green" android:state_pressed="true" />
<item android:color="@color/dark_green" android:state_selected="true" />
<item android:color="@color/dark_green" android:state_focused="true" />
<item android:color="@color/dark_green" android:state_checkable="true" />
<item android:color="@color/dark_green" android:state_checked="true" />
<item android:color="@color/dark_green" android:state_checkable="true" />
<item android:color="@color/dark_green" android:state_window_focused="true" />
</selector>
with using select_item when it says to change color when clicked, and i tried all its properties but to no avail
I wish it would change the item color when I click on it