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/ApplovinBanner ad(with fb/Meta).add
dependencyinbuild.gradleof applovin and fb.(if you use other network then add theirdependencywith applovin. (always check latest dependency version- here)add this code me
manifests.xmlbottom. Here invalueput yoursdk keyyou can find it inApplovin >Account > Keys > sdk KeyPlace
Banner adcode omxmlwhere you wantJava code
Also add
Internet permissionin app.If you use
facebook/Meta adsthen must usenetwork_security_config. make thisxmlinsideres > 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.xmlThanks.
Happy Coding:)