Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set primary and secondary texts' typeface color #11

Open
IAmDarush opened this issue May 29, 2020 · 1 comment
Open

Can't set primary and secondary texts' typeface color #11

IAmDarush opened this issue May 29, 2020 · 1 comment

Comments

@IAmDarush
Copy link

I'm using the following method to set the typeface color. However, withPrimaryTextTypefaceColor() and withSecondaryTextTypefaceColor() don't seem to be working.

val styles = NativeTemplateStyle.Builder()
          .withMainBackgroundColor(ColorDrawable(resources.getColor(R.color.colorWhite)))
          .withPrimaryTextSize(16f)
          .withPrimaryTextTypefaceColor(resources.getColor(R.color.colorRed))
          .withPrimaryTextTypeface(ResourcesCompat.getFont(requireContext(), R.font.lato_regular))
          .withSecondaryTextSize(14f)
          .withSecondaryTextTypefaceColor(resources.getColor(R.color.colorGreen))
          .withSecondaryTextTypeface(ResourcesCompat.getFont(requireContext(), R.font.lato_regular))
          .withTertiaryTextTypefaceColor(resources.getColor(R.color.colorBlack))
          .withCallToActionTextSize(14f)
          .withCallToActionTextTypeface(ResourcesCompat.getFont(requireContext(), R.font.lato_bold))
          .withCallToActionTypefaceColor(resources.getColor(R.color.colorWhite))
          .withCallToActionBackgroundColor(ColorDrawable(resources.getColor(R.color.colorAdCallToAction)))
          .build()

        binding.bannerAd.setStyles(styles)
@IAmDarush IAmDarush changed the title Can't set primary text typeface color Can't set primary and secondary texts' typeface color May 29, 2020
@marchbold
Copy link

There is a bug in the TemplateView when checking colours.

if (primaryTypefaceColor > 0 && primaryView != null) {
  primaryView.setTextColor(primaryTypefaceColor);
}

As colours are normally ARGB values, the first bit is normally set which gets treated as a negative value and fails this test.

Changing all these tests to be != 0 seemed to work for me.

int primaryTypefaceColor = styles.getPrimaryTextTypefaceColor();
if (primaryTypefaceColor != 0 && primaryView != null)
{
	primaryView.setTextColor( primaryTypefaceColor );
}

int secondaryTypefaceColor = styles.getSecondaryTextTypefaceColor();
if (secondaryTypefaceColor != 0 && secondaryView != null)
{
	secondaryView.setTextColor( secondaryTypefaceColor );
}

int tertiaryTypefaceColor = styles.getTertiaryTextTypefaceColor();
if (tertiaryTypefaceColor != 0 && tertiaryView != null)
{
	tertiaryView.setTextColor( tertiaryTypefaceColor );
}

int ctaTypefaceColor = styles.getCallToActionTypefaceColor();
if (ctaTypefaceColor != 0 && callToActionView != null)
{
	callToActionView.setTextColor( ctaTypefaceColor );
}

https://github.com/googleads/googleads-mobile-android-native-templates/blob/master/nativetemplates/src/main/java/com/google/android/ads/nativetemplates/TemplateView.java#L120-L143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants