private MyTargetView adView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
// Enabling debug mode
// MyTargetView.setDebugMode(true);
// Create an instance of MyTargetView
adView = new MyTargetView(this);
// Set slot id
adView.setSlotId(YOUR_SLOT_ID);
// optional: if not set, banner will be adaptive
adView.setAdSize(AdSize.ADSIZE_320x50);
}
private MyTargetView adView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.activityLayout);
// Create an instance of MyTargetView
adView = new MyTargetView(this);
// Set slot id
adView.setSlotId(YOUR_SLOT_ID);
// Set the LayoutParams
adViewLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
adViewLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adView.setLayoutParams(adViewLayoutParams);
// Set the event listener
adView.setListener(new MyTargetView.MyTargetViewListener()
{
@Override
public void onLoad(MyTargetView myTargetView)
{
// The ad is successfully loaded. Start displaying ad
layout.addView(adView);
}
@Override
public void onNoAd(String reason, MyTargetView myTargetView)
{
}
@Override
public void onShow(MyTargetView myTargetView)
{
}
@Override
public void onClick(MyTargetView myTargetView)
{
}
});
// Start loading ad
adView.load();
}
@Override
protected void onDestroy()
{
if (adView != null) adView.destroy();
super.onDestroy();
}
<com.my.target.ads.MyTargetView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/view_ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:myTarget_isRefreshAd="false" // turning off banner rotation
app:myTarget_adSize="banner_320x50" // set format, possible values: banner_320x50, banner_30x250, banner_728x90, adaptive
app:myTarget_slotId="7250"> // slot number
</com.my.target.ads.MyTargetView>
// Disable automatic ad rotation
adView.setRefreshAd(false);
moPubView = new MoPubView(this);
Map<String, Object> localExtras = new HashMap<>();
...
localExtras.put("mytarget_adsize", MyTargetView.AdSize.BANNER_320x50);
moPubView.setLocalExtras(localExtras);