Reputation: 2814
I have a Webview and Advert in my xml:
<WebView
android:id="@+id/webView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="5dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@+id/adView" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-3940256099942544/6300978111"/>
How do I access adView
in my java code and check the value of app:adSize
?
How do I change its value to "LARGE_BANNER"
so that the Webview automatically resizes?
Upvotes: 1
Views: 48
Reputation: 262
To retrieve the AdView in the code. From the right context call findViewById and assign it to an AdView Object
AdView adView = findViewById(R.id.adView);
To get the AdSize
AdSize adSize = adView.getAdSize();
To set an AdSize
adView.setAdSize(AdSize.LARGE_BANNER);
Upvotes: 1