There is no menu item in your ActionBar . This way you can hide the ActionBar and place the ad on top of the Tab . In your MainActivity, call:
... setContentView(R.layout.activity_main); getSupportActionBar().hide();
And your layout for activity_main should look like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" ads:adSize="SMART_BANNER" android:layout_alignParentTop="true" ads:adUnitId="@string/ad_unit_id" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/adView"/> </RelativeLayout>
Consider using the Toolbar and you will find a better way. And if you use Toolbar , your layout should look like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" android:layout_alignParentTop="true" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" app:adSize="SMART_BANNER" app:adUnitId="@string/ad_unit_id" android:layout_below="@+id/toolbar" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/adView"/> </RelativeLayout>
Anggrayudi h
source share