我试图在用Kotlin编写的android应用上显示Facebook广告,但是每次我尝试添加显示错误的代码时,我都到处搜索但找不到Kotlin版本
adView = new AdView(this, "YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50);
// Find the Ad Container
LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container);
// Add the ad view to your activity layout
adContainer.addView(adView);
// Request an ad
adView.loadAd();
答案 0 :(得分:0)
Android Studio提供了从Java到Kotlin的转换工具。要找到它,请双击SHIFT,然后键入“将Java转换为Kotlin”。
adView = AdView(this, "YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50)
// Find the Ad Container
val adContainer = findViewById<LinearLayout>(R.id.banner_container)
// Add the ad view to your activity layout
adContainer.addView(adView)
// Request an ad
adView.loadAd()
或使用kotlin扩展名
adView = AdView(this, "YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50)
// Find the Ad Container and add the ad view to your activity layout
banner_container.addView(adView)
// Request an ad
adView.loadAd()