在自定义视图中显示广告横幅
Show an advert banner in a Custom view
我有一个自定义视图 activity,我想在其中显示一个广告。只是屏幕底部的横幅视图。我正在使用 Appodeal 的 API 来投放广告。
到目前为止,这是我尝试过的:
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();
}
}
}
任何帮助将不胜感激!
您可以使用 xml 布局,例如:
<RelativeLayout
...>
<PathToCustomView.CustomView
...
/>
<PathToBannerView.BannerView
android:below="+id/myCustomviewId"
...
/>
</RelativeLayout>
我有一个自定义视图 activity,我想在其中显示一个广告。只是屏幕底部的横幅视图。我正在使用 Appodeal 的 API 来投放广告。 到目前为止,这是我尝试过的:
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();
}
}
}
任何帮助将不胜感激!
您可以使用 xml 布局,例如:
<RelativeLayout
...>
<PathToCustomView.CustomView
...
/>
<PathToBannerView.BannerView
android:below="+id/myCustomviewId"
...
/>
</RelativeLayout>