skydoves / ExpandableLayout

🦚 An expandable layout that shows a two-level layout with an indicator.
Apache License 2.0
833 stars 54 forks source link

Spinner icon color only changes one time programmatically #32

Open MohamedEmish opened 2 years ago

MohamedEmish commented 2 years ago

Please complete the following information:

Describe the Bug:

For the expansion spinner icon, I set its color from the XML file to be gray

<com.skydoves.expandablelayout.ExpandableLayout android:id="@+id/requestFailedExpandLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/_12sdp" android:layout_marginEnd="@dimen/_12sdp" app:expandable_duration="300" app:expandable_isExpanded="false" app:expandable_parentLayout="@layout/request_failed_header_layout" app:expandable_secondLayout="@layout/request_failed_body_layout" app:expandable_showSpinner="true" app:expandable_spinner_animate="true" app:expandable_spinner_color="@color/gray_8b8b8b" />

then I added a listener on the layout when it's expanded the icon should be blue else should be gray

setOnExpandListener { if (isExpanding) { parentLayout.backgroundTintList = ContextCompat.getColorStateList(requireContext(), R.color.blue_daebfd) spinnerColor = R.color.colorPrimary parentLayout.findViewById<MaterialTextView>(R.id.tvRecommendationExpandTitle).setTextColor(ContextCompat.getColor(requireContext(), R.color.colorPrimary)) } else { parentLayout.backgroundTintList = ContextCompat.getColorStateList(requireContext(), R.color.gray_c7c7c7) spinnerColor = R.color.gray_8b8b8b parentLayout.findViewById<MaterialTextView>(R.id.tvRecommendationExpandTitle).setTextColor(ContextCompat.getColor(requireContext(), R.color.gray_8b8b8b)) } }

but after one single change, the color never changes again.

Expected Behavior:

the spinner icon color to be always changeable

MohamedEmish commented 2 years ago

I fixed that using this line to set the spinner icon color and it worked ((getChildAt(0) as FrameLayout)[1] as ImageView).imageTintList = ContextCompat.getColorStateList(requireContext(), R.color.gray_8b8b8b)