A simple way to implement native ads in your Jetpack Compose Android project.
Add the dependency in your app level build.gradle
:
dependencies {
implementation 'io.github.farimarwat:admobnative-compose:1.3'
implementation 'com.google.android.gms:play-services-ads:22.6.0' // Required dependency
}
Add the below in Manifest
<application
...
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="${ADMOB_API_KEY}" />
</application>
The very basic example:
val adState = rememberNativeAdState(
context = LocalContext.current,
adUnitId = "your_ad_unit_id",
refreshInterval = 60000L
)
BannerAdAdmobSmall(
context = LocalContext.current,
loadedAd = adState
)
Only two types of banners available:
BannerAdAdmobSmall()
BannerAdAdmobMedium()
val customColors = AdColors(
headlineText = Color.White,
bodyText = Color.Gray,
buttonText = Color.Black,
badgeText = Color.White
)
BannerAdAdmobSmall(
context = LocalContext.current,
loadedAd = adState,
adColors = customColors
)
val adState = rememberNativeAdState(
context = LocalContext.current,
adUnitId = "your_ad_unit_id",
refreshInterval = 60000L,
onAdLoaded = {
// Handle successful ad load
},
onAdFailedToLoad = { error ->
// Handle ad load failure
}
)
BannerAdAdmobSmall(
context = LocalContext.current,
loadedAd = adState,
adBackground = yourCustomDrawable,
actionButtonBackground = yourButtonDrawable,
badgeBackground = yourBadgeDrawable
)