android - How to use attributes to change text color from activity -
this code
textview text_language_name4 = (textview)view.findviewbyid(r.id.text); if (text_language_name4 != null) { int text_color4 = selected ? getresources().getcolor(r.color.readcolor) : getresources().getcolor(r.color.readcolor); text_language_name4.settextcolor(text_color4); text_language_name4.setduplicateparentstateenabled(true); }
when using r.attr.mytheme app forces close
any suggestions using attr change color of text view
for theme color try this:
typedvalue tv = new typedvalue(); theme theme = context.gettheme(); boolean success = theme.resolveattribute(r.attr.theme_color, tv, true); int colorfromtheme; if(success) colorfromtheme = tv.data; else // value not found....
now set,
textview.settextcolor(colorfromtheme);
Comments
Post a Comment