繁体   English   中英

在所有活动中显示恒定的admob广告横幅

[英]Show a constant admob ad banner in all the activities

我正在开发一个android应用程序,我在每个活动的底部都嵌入了admob广告,并且在所有活动中都显示了admob广告,但是我想在所有活动中始终显示一个admob广告,该广告始终显示,而不会在切换过程中破坏自身活动,如果有人知道该问题的解决方案,请帮助我,我有3个活动,并且我还尝试创建一个基类,并使用该基类扩展所有活动,并调用创建和加载广告的函数,但仍然同样的问题,我必须在每个活动类中调用此函数,因此,每当它发送请求以加载广告并仅在其调用的期望活动上显示时,我都需要在所有三个活动上展示一个广告,而不是x。 ...

没有办法做到这一点。 正如Ellis所说,您只想在用户花费大部分时间的情况下展示广告。

可能有一种方法可以做到这一点。 但是为此,您可能需要完全重组应用程序UI。 您可以在应用程序中保留一项活动,然后将所有实际活动转换为片段。 然后,您将只在同一活动中交换片段。 我不会推荐这个。

不知道这是否对您有帮助。 试试这个代码。 另外,如果需要,请尝试对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>

希望这可以帮助..! Android开发愉快!!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM