3

In our project we set group name via Spannable with colored icon. When I open activity this works fine. Then I go to next screen where we have same Spannable string but with different icon tint. This screen also works fine with correct color. But if I press Back button and return to previous activity, it will show me wrong tint color on icon(actually tint color would be same as on the screen that I returned from). This problem is observed on old Android versions: JellyBean, KitKat. Below is the function that gets me Spannable string.

public Spannable getNameSpannable(int iconColor){
ImageSpan lockIcon = new ImageSpan(getTintedDrawable(R.drawable.icon_lock, iconColor), ImageSpan.ALIGN_BASELINE);
Spannable spannableGroupName = new SpannableString(" " + getName());
spannableGroupName.setSpan(lockIcon, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
return spannableGroupName;
}
private Drawable getTintedDrawable(int drawableResource, int color) {
        Drawable drawable = DrawableCompat.wrap(App.d(drawableResource));
        DrawableCompat.setTint(drawable, App.c(color));
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        return drawable;
    }
Rafael
  • 6,091
  • 5
  • 54
  • 79

0 Answers0