Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logcat says: "Resource has unresolved theme attributes"

logging my app my Logcat says: WARN: ... has unresolved theme attributes! Consider using Resources.getDrawable(int, Theme) or Context.getDrawable(int).

the code which produces the warning:

    if (mCards.get(position).isFavorite()) {
        viewHolder.mIbStar
                .setImageDrawable(mContext.getResources()
                                          .getDrawable(R.drawable.btn_is_fav));
    } else {
        viewHolder.mIbStar
                .setImageDrawable(mContext.getResources()
                                          .getDrawable(R.drawable.btn_isnt_fav));
    }

I searched for this log, but didn't find anything useful. How knows whats the issue? The program is stable, so no Nullpointer..

Thanks in advance

like image 593
Martin Pfeffer Avatar asked Mar 08 '15 21:03

Martin Pfeffer


1 Answers

The problem is that the system can't find the associated theme to resolve these attributes values. That's why the logcat suggest you to use the Resources.getDrawable(int, Theme) method providing the theme, or to use the Context.getDrawable(int) method where the Context will use its current theme :

Return a drawable object associated with a particular resource ID and styled for the current theme.

Moreover, according to the Android official documentation : http://developer.android.com/reference/android/content/res/Resources.html#getDrawable(int)

This method was deprecated in API level 22. Use getDrawable(int, Theme) instead.

and more specifically

Note: To obtain a themed drawable, use Context.getDrawable(int) or getDrawable(int, Theme) passing the desired theme.

Consider replacing

mContext.getResources().getDrawable(int) 

by

mContext.getDrawable(int)

such as proposes it the logcat.

like image 125
Romain R. Avatar answered Oct 17 '22 07:10

Romain R.