Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 611 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Android Kotlin - AdView adSize: val cannot be reassigned

#1
MobileAds.initialize(this) { }

val adViewBottom = AdView(this)
adViewBottom.adSize = AdSize.BANNER

This worked before I updated the library, now I get

val cannot be reassigned

on

adViewBottom.adSize

changing `val` to `var` doesn't solve it
Reply

#2
Admob 21.0.0 changed the way to set ad size directly.
You can use the `setAdSize` method.

```kotlin
MobileAds.initialize(this) { }

val adViewBottom = AdView(this)
adViewBottom.setAdSize(AdSize.BANNER)
// adViewBottom.setAdSize(AdSize.FULL_BANNER)
// adViewBottom.setAdSize(... Anchored adaptive banner size ...)
```
Reply

#3
If you updated adMob dependency to`implementation 'com.google.android.gms:play-services-ads:21.1.0'` And your intention is to use Anchored adaptive banner, most probably you will get that error. Here is the solution that works for me.

MobileAds.initialize(this) {}

adView = AdView(this)//instance of adView
//get width of a device from window manager
val display = windowManager.defaultDisplay
val outMetrics = DisplayMetrics()
display.getMetrics(outMetrics)

val density = outMetrics.density

var adWidthPixels = adContainerView.width.toFloat()
if (adWidthPixels == 0f) {
adWidthPixels = outMetrics.widthPixels.toFloat()
}

val adWidth = (adWidthPixels / density).toInt()

adView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth))

Reply

#4
Set in this way

adViewBottom.setAdSize(AdSize.BANNER)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through