Jetpack Compose Interoperability: XML + Jetpack Compose for AdMob Implementation
So you wanted to create an app using Jetpack Compose with AdMob. What’s the easiest way?
- Setup your AdMob account https://developers.google.com/admob/android/quick-start
- Setup AdMob dependencies in your Android app project
I. XML Setup
- Create an empty activity (eg.
- Implement this layout in your XML file:
activity_main.xmlwe put the
ConstraintLayoutthat matches the parent’s width and height with the bottom constraint above the
II. MainActivity Setup
- Implement this in your
2. Do your Compose layout :)
- Since we used the XML file, it will follow the declarations in
values(colors, strings, themes) in your
- This is an easier approach if you want to put the ad banner for every screen since you will only have to declare it once.
- This will give you an idea if you want to implement Jetpack Compose in your existing project that uses XMLs for layouts.
If you followed this simple tutorial until the end, thank you so much! I hope you learned something awesome. I am still learning, so if you have any suggestions or opinions, please let me know so I can improve my work. Thanks ✨
Follow me on Twitter: @mjmanaog