1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Drain Droids

Android Studio For Beginners.Mobile Apps.Android Games.

Monday, December 24, 2018

How to Display Admob Banner Ads in a Centralized Bottom of The Main Activity Android Studio



As a beginner to android studio, to show Admob banner ads is not difficult but you still need to learn the steps from many source and use the process that is more simply for you to understand.

Why I mentioned centralized bottom is that because you will see that almost every one shows their admob banner ads at the center of the bottom, this is the best position for banner ads.

When I first started, I find it difficult showing my banner ads at the bottom and central, most of the time, it always go up the page when I want it at bottom.

So this simple guide will show you how to achieve that without stress.




   STEP 1

GO TO BUILD.GRADLE PROJECT AND PASTE BELLOW CODE IN JCENTER
                                                      AND SYN PROJEC

maven {
            url "https://maven.google.com"
        }

  STEP 2
GO TO BUILD.GRADLE APP AND PASTE BELLOW CODE IN DEPENDENCIES
                                           AND SYN PROJEC

implementation 'com.google.android.gms:play-services-ads:15.0.0'

STEP 3
IMPORT THE BELLOW CODE IN JAVA

import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

                                                  
 STEP 4
ON JAVA, PASTE BELLOW CODE UNDER  AppCampatActivity
private AdView mAdView;

STEP 5
ON JAVA PASTE BELLOW CODE ON onCreate

mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        // Code to be executed when an ad finishes loading.
    }

    @Override
    public void onAdFailedToLoad(int errorCode) {
        // Code to be executed when an ad request fails.
    }

    @Override
    public void onAdOpened() {
        // Code to be executed when an ad opens an overlay that
        // covers the screen.
    }

    @Override
    public void onAdLeftApplication() {
        // Code to be executed when the user has left the app.
    }

    @Override
    public void onAdClosed() {
        // Code to be executed when when the user is about to return
        // to the app after tapping on an ad.
    }
});


Watch The Video Here






 FINAL STEP 6

PASTE BELLOW CODE IN THE XML

THIS CODE WILL MAKE BANNER SHOW AT BOTTOM AND CENTRALIZED
Always ensure that you are working with the test ID until you are ready to publish your work.

<RelativeLayout
        android:id="@+id/ad_holder"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="bottom" >

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        app:adSize="BANNER"
        app:adUnitId="ca-app-pub-3940256099942544/6300978111"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="32dp"
        tools:layout_editor_absoluteY="3dp"></com.google.android.gms.ads.AdView>
    </RelativeLayout>

                                                                     NOTE

IF YOU WANT TO DISPLAY ADS ON THE MAIN ACTIVITY PAGE, YOUR CODDING WILL BE WITHING
1-MAIN ACTIVITY XML
2-MAIN ACTIVITY JAVA

IF YOU WANT TO DISPLAY ADS ON THE SECOND ACTIVITY PAGE, YOUR CODDING WILL BE WITHING
1-SECOND ACTIVITY XML
2-SECOND ACTIVITY JAVA