Show a constant admob ad banner in all the activities

寵の児 提交于 2019-12-20 04:33:02

问题


I am working on an android application, i have embedded admob ad at the bottom of each activity and its shows ad in all activities, but i want to show a constant admob ad in all the activities that displays all the time without destroy itself during switching activities, please help me if any one know the solution for this problem, i have 3 activities and i also try to create a base class and extends all activities with this base class and call the function which creates and load the ad, but still the same issue i have to call this function from every activity class so every time it sends request to load ad and display just on the desire activity from which it calls, i need to show a one ad on all the three activities, thanx in advance....


回答1:


There is no way to do this. And as Ellis says you only want to display an ad where your user spends most of their time.




回答2:


There may be one way to do this. But for that, you might need to completely restructure your app UI. You could keep one activity in your app, and convert all the actual activities into fragments. Then, you will just swap fragments inside the same single activity. I wouldn't recommend this though.




回答3:


Not sure if this will help you. Give this code a try. Also, if required, try using the child fragment approach to View Pager.

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true"
        android:layout_height="match_parent"
        android:layout_marginBottom="50dp">

        <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:orientation="vertical">


            <include android:id="@+id/toolbar_actionbar"     layout="@layout/toolbar_default"
                android:layout_width="match_parent" android:layout_height="wrap_content" />

            <FrameLayout android:id="@+id/container21" android:layout_width="match_parent"
                android:clickable="true" android:layout_height="match_parent" />
        </LinearLayout>

        < com.myapp.isgreat.ScrimInsetsFrameLayout android:id="@+id/scrimInsetsFrameLayout"
            android:layout_width="@dimen/navigation_drawer_width" android:layout_height="wrap_content"
            android:fitsSystemWindows="true" android:layout_gravity="start" app:insetForeground="#4000"
            android:elevation="10dp">
            <fragment android:id="@+id/fragment_drawer"
                android:name="com.my.appisgreat.NavigationDrawerFragment"
                android:layout_width="@dimen/navigation_drawer_width"
                android:layout_height="match_parent" android:fitsSystemWindows="true"
                app:layout="@layout/fragment_navigation_drawer"
                tools:layout="@layout/fragment_navigation_drawer" />
        </com.myapp.isgreat.ScrimInsetsFrameLayout>


    </android.support.v4.widget.DrawerLayout>
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>

    </RelativeLayout>

Hope this helps..! Happy Android development.!



来源:https://stackoverflow.com/questions/22379384/show-a-constant-admob-ad-banner-in-all-the-activities

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!