https://kotlinlang.org logo
#compose
Title
# compose
a

amar_1995

11/13/2019, 9:27 AM
Can we use
setContentView
which is responsible to load xml layout and
setContent
in single activity class ?
l

Luca Nicoletti

11/13/2019, 9:37 AM
setContent
is calling
setContentView
internally so it will override it
Up to you, the second one called will be the one you’ll see
a

amar_1995

11/13/2019, 10:39 AM
So is it possible to add old xml layout and on top of it add compose ui.
l

Luca Nicoletti

11/13/2019, 10:40 AM
No, that's not what overrides means
m

Michal Bacik

11/13/2019, 12:52 PM
I've read somewhere that there will be
@GenerateView
annotation that will generate a view from
@Composable
function, then you'll be able to mix compose with classic view hierarchy.
l

Luca Nicoletti

11/13/2019, 12:53 PM
But you won't be able to use setcontent and setcontentview all together
m

Michal Bacik

11/13/2019, 12:55 PM
That's true, compose internally uses setcontentview for its own working view.
a

amar_1995

11/13/2019, 12:58 PM
So, suppose we have some old android project based on layout xml and we want to integrate it with compose. Then, we can only create new view in compose or replace old layout xml with new compose ui.
m

Michal Bacik

11/13/2019, 1:01 PM
You should be able to integrate compose at various levels. Maybe replace entire UI for Activity, or implement just specific views as compose items.
a

amar_1995

11/13/2019, 1:05 PM
Copy code
setContentView(R.layout.main_login)
        setContent {
            MaterialTheme(
                colors = lightThemeColors,
                typography = themeTypography
            ) {
                MonitorScreenCompose(id, applicationContext, this)
            }
        }
In above code there is one layout and other one is compose ui. I want to first display layout from xml and below that layout, I want to add compose ui. Is it possible ?
l

Luca Nicoletti

11/13/2019, 1:05 PM
No.
a

amar_1995

11/13/2019, 1:06 PM
Okay
l

Luca Nicoletti

11/13/2019, 1:06 PM
override
does not mean
add to bottom
a

Adam Powell

11/13/2019, 1:34 PM
There's a version of
setContent
as a ViewGroup extension that you can try out
l

Luca Nicoletti

11/13/2019, 1:35 PM
Yep, that would work, it’s accepting the rootView in which it will ” _inflate_” the composable function, right?
a

Adam Powell

11/13/2019, 1:35 PM
Yeah. It'll add the compose host view to the ViewGroup you supply
👍🏼 2
a

amar_1995

11/15/2019, 7:17 AM
@Adam Powell Is there any demo on how to add compose host view to the viewGroup ?
10 Views