mattinger
02/04/2022, 3:10 PMclass TagLabel @JvmOverloads constructor(
context: Context, attrs:
AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
init {
initialize(attrs)
}
private fun initialize(attrs: AttributeSet?) {
val a = context.obtainStyledAttributes(attrs, intArrayOf(android.R.attr.text))
val text = a.getText(0).toString()
a.recycle()
val delegateView = ComposeView(context).apply {
setContent {
Text(text = text)
}
}
addView(delegateView)
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="<http://schemas.android.com/apk/res-auto>">
<TagLabel
android:layout_width="100dp"
android:layout_height="100dp"
android:text="Foobar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Arjun Achatz
02/04/2022, 4:38 PMmattinger
02/04/2022, 7:04 PM