Skip to content

Instantly share code, notes, and snippets.

@cbedoy
Created March 26, 2020 19:58
Show Gist options
  • Select an option

  • Save cbedoy/c5336d4ebcc12f063d5c8ecfc8c3b2e8 to your computer and use it in GitHub Desktop.

Select an option

Save cbedoy/c5336d4ebcc12f063d5c8ecfc8c3b2e8 to your computer and use it in GitHub Desktop.
fun TextView.setCollapseExpand(collapsibleView: View, onCollapse: () -> Unit, onExpand: () -> Unit) {
setCompoundDrawablesWithIntrinsicBounds(null, null, DrawableConstants.ic_expand_section.createDrawable(), null)
setOnClickListener {
when (collapsibleView.visibility) {
View.GONE -> {
collapsibleView.visibility = View.VISIBLE
setCompoundDrawablesWithIntrinsicBounds(null, null, DrawableConstants.ic_collapse_section.createDrawable(), null)
onExpand()
}
View.VISIBLE -> {
collapsibleView.visibility = View.GONE
setCompoundDrawablesWithIntrinsicBounds(null, null, DrawableConstants.ic_expand_section.createDrawable(), null)
onCollapse()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment