Home > Software design >  Is it possible to integrate jetpack compose compose with xml?
Is it possible to integrate jetpack compose compose with xml?

Time:03-22

I have done the entire project (with 3 activities)in jetpack compose. I need one activity to be done with xml and kotlin as I don't know how to do it in jetpack(I'm new to both). Is it possible to integrate the new activity with the rest of the code?

CodePudding user response:

Jetpack Compose and XML view based system are interoperable.

I need one activity to be done with xml

You can add Android Views in Compose

A simple example :

AndroidView(
    viewBlock = { context ->
        val myView = LayoutInflater.from(context).inflate(R.layout.my_layout, null, false)
        val text = myView.findViewById<TextView>(R.id.text)
        // do things
        myView
    },
    update = { view ->
        // update the view/trigger recomposition
    }
)

CodePudding user response:

Yes. You can use both XML and Compose in the same project. By Default, Android Studio create a xml file when you create a new Activity. That it is all :)

  • Related