Setting up the layout using a template

You can use the standard layout template: The template includes pre-configured settings for all visual ad assets, though they can be customized.

Code example
private fun showAd(nativeAd: NativeAd) {
    val bannerAppearance = createNativeBannerViewAppearance()
    binding.nativeBanner.applyAppearance(bannerAppearance)
    binding.nativeBanner.setAd(nativeAd)
}

private fun createNativeBannerViewAppearance(): NativeTemplateAppearance {
    return NativeTemplateAppearance.Builder()
        .withBannerAppearance(
            BannerAppearance.Builder()
                .setBorderColor(Color.YELLOW).build()
        )
        .withCallToActionAppearance(
            ButtonAppearance.Builder()
                .setTextAppearance(
                    TextAppearance.Builder()
                        .setTextColor(Color.BLUE)
                        .setTextSize(14f).build()
                )
                .setNormalColor(Color.TRANSPARENT)
                .setPressedColor(Color.GRAY)
                .setBorderColor(Color.BLUE)
                .setBorderWidth(1f).build()
        )
        .withImageAppearance(
            ImageAppearance.Builder()
                .setWidthConstraint(
                    SizeConstraint(
                        SizeConstraint.SizeConstraintType.FIXED,
                        60f
                    )
                ).build()
        )
        .withAgeAppearance(
            TextAppearance.Builder()
                .setTextColor(Color.GRAY)
                .setTextSize(12f).build()
        )
        .withBodyAppearance(
            TextAppearance.Builder()
                .setTextColor(Color.GRAY)
                .setTextSize(12f).build()
        )
        .withRatingAppearance(
            RatingAppearance.Builder()
                .setProgressStarColor(Color.CYAN).build()
        )
        .withTitleAppearance(
            TextAppearance.Builder()
                .setTextColor(Color.BLACK)
                .setTextSize(14f).build()
        )
        .build()
}
private void showAd(@NonNull final NativeAd nativeAd) {
    final NativeTemplateAppearance bannerAppearance = createNativeBannerViewAppearance();
    mBinding.nativeBanner.applyAppearance(bannerAppearance);
    mBinding.nativeBanner.setAd(nativeAd);
}

private NativeTemplateAppearance createNativeBannerViewAppearance() {
    return new NativeTemplateAppearance.Builder()
            .withBannerAppearance(
                    new BannerAppearance.Builder()
                            .setBorderColor(Color.YELLOW).build()
            )
            .withCallToActionAppearance(
                    new ButtonAppearance.Builder()
                            .setTextAppearance(
                                    new TextAppearance.Builder()
                                            .setTextColor(Color.BLUE)
                                            .setTextSize(14f).build()
                            )
                            .setNormalColor(Color.TRANSPARENT)
                            .setPressedColor(Color.GRAY)
                            .setBorderColor(Color.BLUE)
                            .setBorderWidth(1f).build()
            )
            .withImageAppearance(
                    new ImageAppearance.Builder()
                            .setWidthConstraint(
                                    new SizeConstraint(
                                            SizeConstraint.SizeConstraintType.FIXED,
                                            60f
                                    )
                            ).build()
            )
            .withAgeAppearance(
                    new TextAppearance.Builder()
                            .setTextColor(Color.GRAY)
                            .setTextSize(12f).build()
            )
            .withBodyAppearance(
                    new TextAppearance.Builder()
                            .setTextColor(Color.GRAY)
                            .setTextSize(12f).build()
            )
            .withRatingAppearance(
                    new RatingAppearance.Builder()
                            .setProgressStarColor(Color.CYAN).build()
            )
            .withTitleAppearance(
                    new TextAppearance.Builder()
                            .setTextColor(Color.BLACK)
                            .setTextSize(14f).build()
            )
            .build();
}

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.