Example of layout using a template
Warning.
This is an archived version of the documentation. Actual documentation for all platforms can be found here.
To customize the layout and design, you can use a standard template or create your own design based on a standard template.
Creating your own template-based layout
- Create an instance of the NativeBannerView class and make the preferred settings for it:
final NativeBannerView nativeBannerView = new NativeBannerView(getApplicationContext()); final NativeTemplateAppearance nativeTemplateAppearance = new NativeTemplateAppearance.Builder() .withBannerAppearance(new BannerAppearance.Builder() .setBackgroundColor(Color.GRAY).build()) .withTitleAppearance(new TextAppearance.Builder() .setTextColor(Color.BLUE).build()) ... .build(); nativeBannerView.applyAppearance(nativeTemplateAppearance);
Note.A NativeBannerView instance can be created either programmatically or using an XML file.
Example of layout configuration
final NativeBannerView nativeBannerView = new NativeBannerView(getApplicationContext());
final NativeTemplateAppearance nativeTemplateAppearance =
new NativeTemplateAppearance.Builder()
// Setting the color for the ad frame.
.withBannerAppearance(new BannerAppearance.Builder()
.setBorderColor(Color.YELLOW).build())
// Setting the button parameters.
.withCallToActionAppearance(new ButtonAppearance.Builder()
// Setting the font color and size for the action button label.
.setTextAppearance(new TextAppearance.Builder()
.setTextColor(Color.BLUE)
.setTextSize(14f).build())
// Setting the button color for the normal state and the clicked state.
.setNormalColor(Color.TRANSPARENT)
.setPressedColor(Color.GRAY)
// Setting the color and thickness of the button border.
.setBorderColor(Color.BLUE)
.setBorderWidth(1f).build())
// Setting the image width and the sizing constraint.
.withImageAppearance(new ImageAppearance.Builder()
.setWidthConstraint(new SizeConstraint(SizeConstraint
.SizeConstraintType.FIXED, 60f)).build())
// Setting the font size and color for the age restriction label.
.withAgeAppearance(new TextAppearance.Builder()
.setTextColor(Color.GRAY)
.setTextSize(12f).build())
// Setting the font size and color for the main ad text.
.withBodyAppearance(new TextAppearance.Builder()
.setTextColor(Color.GRAY)
.setTextSize(12f).build())
// Setting the color for filled stars in the rating.
.withRatingAppearance(new RatingAppearance.Builder()
.setProgressStarColor(Color.CYAN).build())
// Setting the font size and color for the ad title.
.withTitleAppearance(new TextAppearance.Builder()
.setTextColor(Color.BLACK)
.setTextSize(14f).build())
.build();
// Applying the settings.
nativeBannerView.applyAppearance(nativeTemplateAppearance);
Note.
When creating your own template-based design, you don't have to make the preferred settings for all the visual elements. Any elements that don't have preferred settings are configured with the default values.