0

I have a Custom view activity and I want to show in it an advert. Just a banner view on the bottom of the screen. I am using Appodeal's API for ads. Here is what I tried so far:

public class main extends AppCompatActivity  {

    BannerView bannerView;
    View customView;

    public static void loadAd(Context context, Activity activity) {
            Appodeal.setTesting(true);
            Appodeal.disableNetwork(context, "cheetah");
            Appodeal.disableLocationPermissionCheck();
            Appodeal.setBannerViewId(R.id.appodealBannerView);
            Appodeal.initialize(activity, context.getString(R.string.app_key), Appodeal.BANNER_VIEW);
            Appodeal.show(activity, Appodeal.BANNER_VIEW);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        customView = new CustomView(this, null);
        setContentView(customView);

        bannerView = new BannerView(this, null);
        bannerView.setId(R.id.appodealBannerView);
    }

    @Override
    protected void onResume() {
        super.onResume();

        loadAd(this, this);
    }

    class CustomView extends View {
        CustomView(Context ctx, AttributeSet attrs) {
            super(ctx, attrs);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);

            bannerView.draw(canvas);

            invalidate();
        }
    }
}

Any help will be appreciated!

Kavach Chandra
  • 770
  • 1
  • 10
  • 25
Da2da2
  • 57
  • 2
  • 3
  • 13

1 Answers1

1

U can use xml layout as below for example:

<RelativeLayout
 ...>
 <PathToCustomView.CustomView
  ...
  />

 <PathToBannerView.BannerView
  android:below="+id/myCustomviewId"
  ...
  />

</RelativeLayout>
ugur
  • 3,604
  • 3
  • 26
  • 57