Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void loadNativeAd() {
- if (AdsConfig.NATIVE_AD_ON_NEWS_DETAIL) {
- TemplateView native_template = findViewById(R.id.my_template);
- MediaView mediaView = findViewById(R.id.media_view);
- AdLoader adLoader = new AdLoader.Builder(this, getResources().getString(R.string.admob_native_unit_id))
- .forUnifiedNativeAd(unifiedNativeAd -> {
- if (sharedPref.getIsDarkTheme()) {
- ColorDrawable colorDrawable = new ColorDrawable(ContextCompat.getColor(this, R.color.colorBackgroundDark));
- NativeTemplateStyle styles = new NativeTemplateStyle.Builder().withMainBackgroundColor(colorDrawable).build();
- native_template.setStyles(styles);
- } else {
- ColorDrawable colorDrawable = new ColorDrawable(ContextCompat.getColor(this, R.color.colorBackgroundLight));
- NativeTemplateStyle styles = new NativeTemplateStyle.Builder().withMainBackgroundColor(colorDrawable).build();
- native_template.setStyles(styles);
- }
- mediaView.setImageScaleType(ImageView.ScaleType.CENTER_CROP);
- native_template.setNativeAd(unifiedNativeAd);
- new Handler().postDelayed(() -> native_template.setVisibility(View.VISIBLE), 1500);
- })
- .withAdListener(new AdListener() {
- @Override
- public void onAdFailedToLoad(int errorCode) {
- native_template.setVisibility(View.GONE);
- }
- })
- .build();
- adLoader.loadAd(Tools.getAdRequest(this));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement