Mon thème:resolveAttribute retourne toujours null pour les attributs
<style name="AppThemeDark" parent="Theme.AppCompat">
<item name="AppButton">@drawable/standard_dark_button_selector</item>
</style>
Ce code j'utiliser pour obtenir un thème drawable:
public static Drawable getThemedDrawable(Context context, int resource) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(resource, typedValue, true);
if(typedValue.resourceId == 0) {
return context.getResources().getDrawable(R.drawable.standard_theme_not_found);
}
else
return context.getResources().getDrawable(typedValue.resourceId);
}
Et voici l'appel direct:
positive.setBackgroundDrawable(Theme.getThemedDrawable(getBaseContext(), R.attr.AppButton));
Le typedValue.resourceId est toujours 0 et ne renvoie aucun identifiant de ressource drawable réel, dans ce cas il renvoie toujours R.drawable.standard_theme_not_f ound
Lorsque j'utilise ce code avec des couleurs (venant de typedValue.data) son rempli et fonctionne.
Comment puis-je résoudre ce problème?