1. 레이아웃에서 아래와 같이 선언합니다
2.
binding = DataBindingUtil.inflate<FragmentMainBinding>(inflater, R.layout.fragment_main, container, false).apply {
// lifecycleOwner = viewLifecycleOwner
}
binding.composeView.setContent {
VlmWorldTheme {
// A surface container using the 'background' color from the theme
// Surface(color = MaterialTheme.colors.background) {
EnterPoint(userViewModel)
// }
}
}
이와 같이 호출하면 사용가능합니다
변수 연결 예제
var checkable = mutableStateOf(false)
binding.m7compose.setOnClickListener {
checkable.value = !checkable.value
}
binding.composeView.setContent {
val composeAble by checkable
if(composeAble)
Text("helloTest")
}
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/m7clo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginBottom="1dp"
android:elevation="6dp"
android:orientation="horizontal"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/m7compose"
style="@style/text_view_contents_item_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="1dp"
android:text="컴포즈테스트"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
'Android Dev > Compose' 카테고리의 다른 글
Compose - Text Trial / OutlinedTextField / Keyboard (0) | 2021.12.07 |
---|---|
Compose - Gradient Color Set (0) | 2021.12.07 |
Compose - LazyColumn Flickering Issue or non data(Firebase flow) 플리커링 혹은 데이터없음 문제해결 (0) | 2021.09.05 |
Compose - LazyColumn + Counting Method + Firebase + Flow 예제 (0) | 2021.09.04 |
Compose Layout trial (0) | 2021.08.31 |