, although I'm only doing this in Android. You can see an example on how these banners/interstatials looks like in my app:
.
Then for banner ads:
- Go to /src/codename1/impl/android/AndroidImplementation.java and replace initSurface() by this:
public static MoPubView moPubView;
/**
* init view. a lot of back and forth between this thread and the UI thread.
*/
private void initSurface() {
//layout for whole screen
RelativeLayout rl = new RelativeLayout(activity);
rl.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
//add banner
moPubView = new MoPubView(getContext());
moPubView.setAdUnitId(<your mopub id>); // Enter your
// Ad Unit
// ID from
moPubView.loadAd();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); // You might want to tweak these to WRAP_CONTENT
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
final int dps = 50;
final float scale = getContext().getResources().getDisplayMetrics().density;
final int pixels = (int) (dps * scale + 0.5f);
//add implementation
relativeLayout = new RelativeLayout(activity);
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
lp2.setMargins(0, 0, 0, pixels);
relativeLayout.setLayoutParams(lp2);
relativeLayout.setFocusable(false);
myView = new AndroidView(activity, AndroidImplementation.this);
myView.setVisibility(View.VISIBLE);
relativeLayout.addView(myView);
myView.setVisibility(View.VISIBLE);
int id = activity.getResources().getIdentifier("main", "layout", activity.getApplicationInfo().packageName);
RelativeLayout root = (RelativeLayout) LayoutInflater.from(activity).inflate(id, null);
rl.addView(relativeLayout);
root.addView(rl);
root.addView(moPubView, lp);
activity.setContentView(root);
myView.requestFocus();
}
- Go to /res/layout/main.xml in your project and replace it with this:
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff000000" >
</RelativeLayout>
For interstatials: