本文整理汇总了Java中com.google.android.gms.ads.formats.NativeContentAdView.findViewById方法的典型用法代码示例。如果您正苦于以下问题:Java NativeContentAdView.findViewById方法的具体用法?Java NativeContentAdView.findViewById怎么用?Java NativeContentAdView.findViewById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.ads.formats.NativeContentAdView
的用法示例。
在下文中一共展示了NativeContentAdView.findViewById方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepare
import com.google.android.gms.ads.formats.NativeContentAdView; //导入方法依赖的package包/类
@Override
protected void prepare(@NonNull final NativeContentAdView adView, @NonNull final NativeContentAd nativeAd) {
final TextView adTitle = (TextView)adView.findViewById(R.id.ad_title);
final TextView adBody = (TextView)adView.findViewById(R.id.ad_body);
final ImageView adImage = (ImageView)adView.findViewById(R.id.ad_image);
final TextView adCallToAction = (TextView)adView.findViewById(R.id.ad_call_to_action);
adView.setHeadlineView(adTitle);
adView.setBodyView(adBody);
adView.setImageView(adImage);
adView.setCallToActionView(adCallToAction);
}
示例2: populateContentAdView
import com.google.android.gms.ads.formats.NativeContentAdView; //导入方法依赖的package包/类
/**
* Populates a {@link NativeContentAdView} object with data from a given
* {@link NativeContentAd}.
*
* @param nativeContentAd the object containing the ad's assets
* @param adView the view to be populated
*/
private void populateContentAdView(NativeContentAd nativeContentAd,
NativeContentAdView adView) {
// Assign native ad object to the native view.
adView.setNativeAd(nativeContentAd);
adView.setHeadlineView(adView.findViewById(R.id.contentad_headline));
adView.setImageView(adView.findViewById(R.id.contentad_image));
adView.setBodyView(adView.findViewById(R.id.contentad_body));
adView.setCallToActionView(adView.findViewById(R.id.contentad_call_to_action));
adView.setLogoView(adView.findViewById(R.id.contentad_logo));
adView.setAdvertiserView(adView.findViewById(R.id.contentad_advertiser));
// Some assets are guaranteed to be in every NativeContentAd.
((TextView) adView.getHeadlineView()).setText(nativeContentAd.getHeadline());
((TextView) adView.getBodyView()).setText(nativeContentAd.getBody());
((TextView) adView.getCallToActionView()).setText(nativeContentAd.getCallToAction());
((TextView) adView.getAdvertiserView()).setText(nativeContentAd.getAdvertiser());
List<NativeAd.Image> images = nativeContentAd.getImages();
if (images.size() > 0) {
((ImageView) adView.getImageView()).setImageDrawable(images.get(0).getDrawable());
}
// Some aren't guaranteed, however, and should be checked.
NativeAd.Image logoImage = nativeContentAd.getLogo();
if (logoImage == null) {
adView.getLogoView().setVisibility(View.INVISIBLE);
} else {
((ImageView) adView.getLogoView())
.setImageDrawable(logoImage.getDrawable());
adView.getLogoView().setVisibility(View.VISIBLE);
}
// Handle the fact that this could be a Sample SDK native ad, which includes a
// "degree of awesomeness" field.
Bundle extras = nativeContentAd.getExtras();
if (extras.containsKey(SampleCustomEvent.DEGREE_OF_AWESOMENESS)) {
TextView degree = (TextView) adView.findViewById(R.id.appinstall_degreeofawesomeness);
degree.setVisibility(View.VISIBLE);
degree.setText(extras.getString(SampleCustomEvent.DEGREE_OF_AWESOMENESS));
}
}
示例3: populateContentAdView
import com.google.android.gms.ads.formats.NativeContentAdView; //导入方法依赖的package包/类
/**
* Populates a {@link NativeContentAdView} object with data from a given
* {@link NativeContentAd}.
*
* @param nativeContentAd the object containing the ad's assets
* @param adView the view to be populated
*/
private void populateContentAdView(NativeContentAd nativeContentAd,
NativeContentAdView adView) {
adView.setHeadlineView(adView.findViewById(R.id.contentad_headline));
adView.setBodyView(adView.findViewById(R.id.contentad_body));
adView.setCallToActionView(adView.findViewById(R.id.contentad_call_to_action));
adView.setLogoView(adView.findViewById(R.id.contentad_logo));
adView.setAdvertiserView(adView.findViewById(R.id.contentad_advertiser));
// Some assets are guaranteed to be in every NativeContentAd.
((TextView) adView.getHeadlineView()).setText(nativeContentAd.getHeadline());
((TextView) adView.getBodyView()).setText(nativeContentAd.getBody());
((TextView) adView.getCallToActionView()).setText(nativeContentAd.getCallToAction());
((TextView) adView.getAdvertiserView()).setText(nativeContentAd.getAdvertiser());
// Get the video controller for the ad. One will always be provided, even if the ad doesn't
// have a video asset.
VideoController vc = nativeContentAd.getVideoController();
MediaView mediaView = adView.findViewById(R.id.contentad_media);
ImageView mainImageView = adView.findViewById(R.id.contentad_image);
// Apps can check the VideoController's hasVideoContent property to determine if the
// NativeContentAd has a video asset.
if (vc.hasVideoContent()) {
mainImageView.setVisibility(View.GONE);
adView.setMediaView(mediaView);
mVideoStatus.setText(String.format(Locale.getDefault(),
"Video status: Ad contains a %.2f:1 video asset.",
vc.getAspectRatio()));
// Create a new VideoLifecycleCallbacks object and pass it to the VideoController. The
// VideoController will call methods on this object when events occur in the video
// lifecycle.
vc.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
public void onVideoEnd() {
// Publishers should allow native ads to complete video playback before
// refreshing or replacing them with another ad in the same UI location.
mRefresh.setEnabled(true);
mVideoStatus.setText("Video status: Video playback has ended.");
super.onVideoEnd();
}
});
} else {
mediaView.setVisibility(View.GONE);
adView.setImageView(mainImageView);
// At least one image is guaranteed.
List<NativeAd.Image> images = nativeContentAd.getImages();
mainImageView.setImageDrawable(images.get(0).getDrawable());
mRefresh.setEnabled(true);
mVideoStatus.setText("Video status: Ad does not contain a video asset.");
}
// These assets aren't guaranteed to be in every NativeContentAd, so it's important to
// check before trying to display them.
NativeAd.Image logoImage = nativeContentAd.getLogo();
if (logoImage == null) {
adView.getLogoView().setVisibility(View.INVISIBLE);
} else {
((ImageView) adView.getLogoView()).setImageDrawable(logoImage.getDrawable());
adView.getLogoView().setVisibility(View.VISIBLE);
}
// Assign native ad object to the native view.
adView.setNativeAd(nativeContentAd);
}