- Notifications
You must be signed in to change notification settings - Fork0
samyak2403/BannerAds
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- Updated to the latest version of Admob SDK
- Supported on Android SDK 30, 31, 32, 33, 34
- Updated RVAdapter to Kotlin
To maximize your app's revenue by displaying Banner Ads , follow the instructions below.
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'}
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);
BannerAds ads Small Layout | BannerAds ads Medium Layout |
---|---|
![]() | ![]() |
About
No description or website provided.
Topics
Resources
Stars
Watchers
Forks
Packages0
No packages published