I am new to Applovin/Max
. In their documentation position
and size
of Banner
ad set by programmatically.
Thats why BannerAd
override my app's content
.
Banner layout in xml
<com.applovin.mediation.ads.MaxAdView
android:id="@+id/maxBannerAdLayout"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="@dimen/banner_height" />
In documentation banner show progrmatically
adView = new MaxAdView( "YOUR_AD_UNIT_ID", this );
adView.setListener( this );
// Stretch to the width of the screen for banners to be fully functional
int width = ViewGroup.LayoutParams.MATCH_PARENT;
// Get the adaptive banner height.
int heightDp = MaxAdFormat.BANNER.getAdaptiveSize( this ).getHeight();
int heightPx = AppLovinSdkUtils.dpToPx( this, heightDp );
adView.setLayoutParams( new FrameLayout.LayoutParams( width, heightPx ) );
adView.setExtraParameter( "adaptive_banner", "true" );
// Set background or background color for banners to be fully functional
adView.setBackgroundColor( ... );
ViewGroup rootView = findViewById( android.R.id.content );
rootView.addView( adView );
// Load the ad
adView.loadAd();
I have no idea,
How can I connect code with banner layout
?
Here I explain Full process of showing
Max/Applovin
Banner ad
(with fb/Meta).add
dependency
inbuild.gradle
of applovin and fb.(if you use other network then add theirdependency
with applovin. (always check latest dependency version- here)add this code me
manifests.xml
bottom. Here invalue
put yoursdk key
you can find it inApplovin >Account > Keys > sdk Key
Place
Banner ad
code omxml
where you wantJava code
Also add
Internet permission
in app.If you use
facebook/Meta ads
then must usenetwork_security_config
. make thisxml
insideres > xml
(if you not find xml then Right click on res > new > create Directory namedxml
) inside this xml directory create this below xml file.network_security_config.xml
also declare this file in
menifest.xml
Thanks.
Happy Coding:)