NOTE: You must use Android Studio Version 4.2 Beta 2 or above.

Before we create the latest Google Admob Banner Ads, first we have to set up a new project for this. So first we create a project in Android Studio Software. All steps are given below with an image for your better understanding purpose.

STEP: 01

You can click on “Create New Project” then jump next page.

STEP: 02

Now, you must choose “Empty Activity” and then click the Next button and then you can jump next screen/page.

STEP: 03

Now, you can write “Application Name“, “Package Name“, “Save Location“, “Language – JAVA“, “Minimum SDKAPI 19“. After customization of all things then you can click the Finish button. And then you can wait a few minutes while your project is Sync successfully.

STEP: 04

Double click on “manifests” folder.

STEP: 05

Add some use permission for CONNECTIVITY. means you must create an Internet permission method then your ads will show in your mobile application.

<uses-permission android:name="android.permission.INTERNET"/>

STEP: 06

Add Google Admob Ads meta-data to show your ads in the application. You must insert meta-data code under the application section.

<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>

STEP: 07

Now, we can add Admob ads dependency that’s why we can insert the latest Admob dependency. Now double click on Gradle Scripts and again double click on build.gradle(Module: CLICK2CODE.app) here CLICK2CODE is my project name you can click as per your project name and insert the under dependency section given below.

// GOOGLE ADMOB ADS DEPENDENCY
implementation 'com.google.android.gms:play-services-ads:19.6.0'

STEP: 08

Now, all setups will be inserted successfully then you can click the “Sync Now” button which shows the right side top corner of your project screen.

IMPLEMENT A CUSTOM BANNER ADS

First, you can insert banner ads code in your activity_main.xml file that’s why we give you the complete code below. And always remember all Banner Ads code inserted under Linear Layout further if you want to change then you can do it yourself.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/purple_500"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="50dp"
        app:cardCornerRadius="96dp"
        app:cardElevation="3dp">
        <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
    </androidx.cardview.widget.CardView>

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="50dp"
        android:text="CUSTOM\nBANNER ADS"
        android:textAlignment="center"
        android:textAppearance="@style/TextAppearance.AppCompat.Medium"
        android:textColor="@android:color/white"
        android:textStyle="bold" />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="50dp"
        android:gravity="center">

        <Button
            android:id="@+id/nextAdsBtn"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/black"
            android:gravity="center"
            android:text="Next ADS"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            android:textStyle="bold" />


    </RelativeLayout>


</LinearLayout>

Now, we insert some JAVA code in the MainActivity.java file that’s why we have given you all the java code under the onCreate method given below to show your ads completely. If you got any RED marks then simply you can import class else press the keyboard key – “Alt + Enter“.

IF YOU FACING ANY ERROR THEN YOU CAN WATCH OUR TUTORIAL FOR BETTER UNDERSTANDING. CLICK HERE

MobileAds.initialize(this, initializationStatus -> {
});
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Button button = findViewById(R.id.nextAdsBtn);
button.setOnClickListener(v -> {
    Intent intent = new Intent(MainActivity.this, SmartBannerAds.class);
    startActivity(intent);
});

IMPLEMENT A CUSTOM SMART BANNER ADS

First, you can insert banner ads code in your activity_main.xml file that’s why we give you the complete code below. And always remember all Banner Ads code inserted under Linear Layout further if you want to change then you can do it yourself.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/purple_500"
android:orientation="vertical"
tools:context=".SmartBannerAds">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
app:cardCornerRadius="96dp"
app:cardElevation="3dp">
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="CUSTOM\nSMART BANNER ADS"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/white"
android:textStyle="bold" />


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:gravity="center">

<Button
android:id="@+id/nextAdsBtn"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:backgroundTint="@color/black"
android:gravity="center"
android:text="Next ADS"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textStyle="bold" />


</RelativeLayout>


</LinearLayout>

Now, we insert some JAVA code in the MainActivity.java file that’s why we have given you all the java code under the onCreate method given below to show your ads completely. If you got any RED marks then simply you can import class else press the keyboard key – “Alt + Enter“.

MobileAds.initialize(this, initializationStatus -> {
});
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Button button = findViewById(R.id.nextAdsBtn);
button.setOnClickListener(v -> {
    Intent intent = new Intent(MainActivity.this, SmartBannerAds.class);
    startActivity(intent);
});

IMPLEMENT A CUSTOM LARGE BANNER ADS

First, you can insert banner ads code in your activity_main.xml file that’s why we give you the complete code below. And always remember all Banner Ads code inserted under Linear Layout further if you want to change then you can do it yourself.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/purple_500"
android:orientation="vertical"
tools:context=".LargeBannerAds">

<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
app:cardCornerRadius="16dp"
app:cardElevation="3dp">

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="LARGE_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="CUSTOM\nLARGE BANNER ADS"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/white"
android:textStyle="bold" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:gravity="center">

<Button
android:id="@+id/nextAdsBtn"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:backgroundTint="@color/black"
android:gravity="center"
android:text="Next ADS"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textStyle="bold" />


</RelativeLayout>


</LinearLayout>

Now, we insert some JAVA code in the MainActivity.java file that’s why we have given you all the java code under the onCreate method given below to show your ads completely. If you got any RED marks then simply you can import class else press the keyboard key – “Alt + Enter“.

MobileAds.initialize(this, initializationStatus -> {
});
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Button button = findViewById(R.id.nextAdsBtn);
button.setOnClickListener(v -> {
Intent intent = new Intent(MainActivity.this, SmartBannerAds.class);
startActivity(intent);
});

IMPLEMENT A CUSTOM MEDIUM RECTANGLE BANNER ADS

First, you can insert banner ads code in your activity_main.xml file that’s why we give you the complete code below. And always remember all Banner Ads code inserted under Linear Layout further if you want to change then you can do it yourself.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/purple_500"
android:orientation="vertical"
tools:context=".MediumRectangleBannerAds">

<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
app:cardCornerRadius="16dp"
app:cardElevation="3dp">

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="MEDIUM_RECTANGLE"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="CUSTOM\nMEDIUM RECTANGLE BANNER ADS"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/white"
android:textStyle="bold" />


</LinearLayout>

Now, we insert some JAVA code in the MainActivity.java file that’s why we have given you all the java code under the onCreate method given below to show your ads completely. If you got any RED marks then simply you can import class else press the keyboard key – “Alt + Enter“.

MobileAds.initialize(this, initializationStatus -> {
});
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Button button = findViewById(R.id.nextAdsBtn);
button.setOnClickListener(v -> {
Intent intent = new Intent(MainActivity.this, SmartBannerAds.class);
startActivity(intent);
});

*** THANK YOU ***


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *