0

I have a screen that lists all my customs themes. I want to show theme's colors next to its name. So I need unused(not current) theme colors.

Normally, we can do like this way,

Resources.Theme theme = context.getTheme();

theme.resolveAttribute(themeColor, typedValue, true);

But in this situation I must write something like that getTheme(R.style.foo).

How can I go with it?

Arda Kaplan
  • 1,720
  • 1
  • 15
  • 23
  • 1
    You can try this answer https://stackoverflow.com/questions/13719103/how-to-retrieve-style-attributes-programmatically-from-styles-xml – thekekc Jun 04 '20 at 20:42

1 Answers1

0

After lots of searching, I realized this, this not about the theme, it is all about style. Shame on me. So now, because of opening this question, I answer my question.

Firstly you must define what you want

int[] attrs = {R.attr.color_1, R.attr.color_2, R.attr.color_3, R.attr.color_4};

and then you can get them by index

TypedArray ta = holder.itemView.getContext().obtainStyledAttributes(R.style.AppTheme_Pink, attrs);

ViewHelpers.Companion.changeBackgroundSolidColor(holder.color1ImageView, ta.getColor(0, Color.GRAY));
ViewHelpers.Companion.changeBackgroundSolidColor(holder.color2ImageView, ta.getColor(1, Color.GRAY));
ViewHelpers.Companion.changeBackgroundSolidColor(holder.color3ImageView, ta.getColor(2, Color.GRAY));
ViewHelpers.Companion.changeBackgroundSolidColor(holder.color4ImageView, ta.getColor(3, Color.GRAY));

dont forget to recycler

ta.recycle();
Arda Kaplan
  • 1,720
  • 1
  • 15
  • 23