For example I have:
fun View.forEachChildView(closure: (View) -> Unit) {
closure(this)
val groupView = this as? ViewGroup ?: return
val size = groupView.childCount - 1
for (i in 0..size) {
groupView.getChildAt(i).forEachChildView(closure)
}
}
val layout = LinearLayout(context!!)
layout.forEachChildView { it.isEnabled = false }
val view = View(context!!)
view.forEachChildView { it.isEnabled = false }
val fragment = Fragment.instantiate(context, "fragment_id")
fragment.view?.forEachChildView { it.isEnabled = false }