gpt4 book ai didi

Android admob 通过 webview 显示横幅广告

转载 作者:行者123 更新时间:2023-11-29 16:59:01 24 4
gpt4 key购买 nike

我想在 WebView 中显示横幅广告。但不知道该怎么做。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_ptv"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.techndroid.cricketlivestreaming.Ptv">

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

<WebView
android:layout_below="@+id/adView"
android:id="@+id/webStream"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</RelativeLayout>

我希望广告显示在版式的顶部。

我认为它落后于 WebView 。我需要通过 webview 显示

最佳答案

您也可以在 RelativeLayout 中显示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<WebView
android:id="@+id/myWebView"
android:layout_above="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
android:layout_width="match_parent"
android:background="@android:color/transparent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>

</RelativeLayout>

在java中,只要写:

    AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

关于Android admob 通过 webview 显示横幅广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43581338/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com