Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
NotificationsYou must be signed in to change notification settings

samyak2403/BannerAds

Repository files navigation

Update

  • Updated to the latest version of Admob SDK
  • Supported on Android SDK 30, 31, 32, 33, 34
  • Updated RVAdapter to Kotlin

For Developers

To maximize your app's revenue by displaying Banner Ads , follow the instructions below.

How to Use the BannerAds Library

Step 1: Add the JitPack Repository

Add the JitPack repository to your project’s build file:

For Gradle (insettings.gradle for Android Studio Bumblebee or later):

dependencyResolutionManagement {    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)    repositories {        google()        mavenCentral()        maven { url'https://jitpack.io' }// Add this line    }}

Step 2. Add the dependency

dependencies {        implementation 'com.github.samyak2403:BannerAds:1.0.1'}

Layout Example:

Add the following XML layout code to your activity_main.xml:

 <?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:padding="16dp"tools:context=".MainActivity"><!-- Other UI components can go here--><!-- LinearLayout to contain the Banner Ad-->    <LinearLayoutandroid:id="@+id/bannerAdContainer"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:orientation="vertical"android:layout_marginTop="16dp" /><!-- Other UI components can go here--></LinearLayout>

Step 3. In your MainActivity.kt, add the following code to initialize and load the banner ad:

kotlin:

classMainActivity :AppCompatActivity() {overridefunonCreate(savedInstanceState:Bundle?) {super.onCreate(savedInstanceState)      enableEdgeToEdge()      setContentView(R.layout.activity_main)ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets->val systemBars= insets.getInsets(WindowInsetsCompat.Type.systemBars())          v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)          insets      }// Initialize Control class and load the banner adval control=Control(this)val adUnitId= getString(R.string.admob_banner_id)// Fetch the AdMob banner ID from resources      control.loadBannerAd(R.id.bannerAdContainer, adUnitId)  }}
IfyoupreferJava,usethefollowingsetupinyourMainActivity.java:// Initialize Control class and load the banner adControlcontrol =newControl(this);StringadUnitId =getString(R.string.admob_banner_id);// Fetch the AdMob banner ID from resourcescontrol.loadBannerAd(R.id.bannerAdContainer,adUnitId);

Demo

BannerAds ads Small LayoutBannerAds ads Medium Layout

[8]ページ先頭

©2009-2025 Movatter.jp