android training

How to place banner ads in android apps. [ Android studio tutorial ]

Hello, friends. In this android studio tutorial, we will see how we can place banner ads in the android studio. Before that, we will see what are banner ads and what are benefits of using banner ads.

Useful Links

What are banner ads?

The little wider ads at the bottom or upper of app screen are called banner ads. Most of the apps are using these ads because you can have extra revenue with these ads. These are not annoying and most of the user don’t hate banner ads. But keep in mind that you should not provide banner ad near to the buttons because the user will get irritated and he/she will uninstall your app.

Steps to place banner ads

  • Edit file

In here you have to add a line of code. Then click on sync project.

dependencies {
compile fileTree
(dir: ‘libs’, include: [‘*.jar’])
compile ‘’

  • Edit file

Now in main java file add a simple line of code and replace  YOUR_ADMOB_APP_ID string with your AdMob app id. I repeat here you have to type your AdMob app id, Not ad unit. When you will create AdMob account and create a new app. They will give you two ids, First is AdMob app id and other is ad unit. Now type following code in onCreate method.

MobileAds.initialize(this, “YOUR_ADMOB_APP_ID”);


  • Edit the XML file.

Now open the XML file where you want to place a banner ad. Enter the following code and adjust height width according to the need. Please keep in mind that don’t use your original ad unit until your app is ready to be published on play store. Otherwise, your account can be banned because you are violating AdMob policies.



  • Edit again

Now to load ad, enter following code


public class MainActivity extends AppCompatActivity {
 private AdView mAdView;

protected void onCreate(Bundle savedInstanceState) {


mAdView = (AdView) findViewById(;
 AdRequest adRequest = new AdRequest.Builder().build();



Nowyou havee successfully implemented banner ad. If you are facing any problem then you can comment below or read official android developer documentation.



Leave a Reply

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