Can we use `setContentView` which is responsible t...
# compose
a
Can we use
setContentView
which is responsible to load xml layout and
setContent
in single activity class ?
l
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
So is it possible to add old xml layout and on top of it add compose ui.
l
No, that's not what overrides means
m
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
But you won't be able to use setcontent and setcontentview all together
m
That's true, compose internally uses setcontentview for its own working view.
a
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
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
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
No.
a
Okay
l
override
does not mean
add to bottom
a
There's a version of
setContent
as a ViewGroup extension that you can try out
l
Yep, that would work, it’s accepting the rootView in which it will ” _inflate_” the composable function, right?
a
Yeah. It'll add the compose host view to the ViewGroup you supply
👍🏼 2
a
@Adam Powell Is there any demo on how to add compose host view to the viewGroup ?