Google gives the following example of how to use a ComposeView in XML and inflate it in a fragment.
class ExampleFragment : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { // Inflate the layout for this fragment return inflater.inflate( R.layout.fragment_example, container, false ).apply { findViewById<ComposeView>(R.id.compose_view).setContent { // In Compose world MaterialTheme { Text("Hello Compose!") } } } } }
I have an activity written in java, not kotlin. Is it possible to use setContent from a Java activity? If so I am struggling with the syntax.
https://stackoverflow.com/questions/67423907/possible-to-use-layout-a-compose-view-in-and-activity-written-in-java May 07, 2021 at 02:20AM
没有评论:
发表评论