How to get admob in webview?

2019-09-08 17:43发布

问题:

I have a web page that I load via webView. Page has a div block to show an advertize and my task is get this div blok and insert code for adMob. Unfortunatly I doesn't found any docs that describes this approach or even says that it is possible.

If you know something that can help me I will be glad to hear it. Thanks.

回答1:

First advice: do not use webview unless you are forced to.

To display an as in an application, do not use the web one, but an AdView (https://developers.google.com/mobile-ads-sdk/download#downloadandroid)

  <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                         ads:loadAdOnCreate="true"/>

Place your AdView below your Webview and voila!