Cannot use theme attributes in a drawable. Got android.content.res.Resources$NotFoundException error

getidentifier android
android resources
android getresources
android get color from resource
android get drawable from resource
get color from resource android kotlin
android resource id

I got the following shape drawable:

<shape xmlns:android="" android:shape="rectangle" >
    <solid android:color="#222222" />
    <stroke android:width="1dip" android:color="?attr/colorPrimary"/>
        android:bottom="4dp" />

I am setting color attribute from my theme in this line:

<stroke android:width="1dip" android:color="?attr/colorPrimary"/>

Project compiles alright without any issues, but during runtime on a device I got the following problem:

    android.view.InflateException: Binary XML file line #119: Error inflating class TextView
    Caused by: android.content.res.Resources$NotFoundException: File
 res/drawable/bordered_green_solid_textview.xml from drawable resource ID #0x7f07006a

When I replace ?attr/colorPrimary and use for example hex color like #222222 it will run without any problem.

What should I do to use ?attrs in my drawables without problems?

P.S.: My min API level 19

My TextView:

<TextView android:id="@+id/imagesCounter"
            tools:text="67" />

is better way to use color from your color value or use a hex color. if you have to use ?attr value :

  1. you should define color
  2. create file res/value/attrs.xml
  3. define color in a style and set value for your attr
  4. use your attr in drawble

android.content.res.Resources, Error � LocaleDisplayNames. This class holds the current attribute values for a particular theme. Use getDrawableForDensity(int, int, android.content.res. NotFoundException, Throws NotFoundException if the given ID does not the drawable attributes, may be null if the drawable cannot be decoded. Only one value for each qualifier type is supported. For example, if you want to use the same drawable files for Spain and France, you cannot have a directory named drawable-es-fr/. Instead you need two resource directories, such as drawable-es/ and drawable-fr/, which contain the appropriate files. However, you aren't required to actually

Why must you use the ?attr

Just call


Color state list resource, Note: If you want to provide a static color resource, use a simple Color value. which must be "" . So if the first item in the list contains none of the state attributes Drawable arrow_forward page are subject to the licenses described in the Content License. Why GitHub? Features →. Code review; Project management; Integrations; Actions; Packages; Security

After all I found out that for API level like 19 the only possible way is to make separate drawables for different themes of your application.

So first of all you need to declare you new attributes for drawables in values/attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
    <attr name="nav_bar_header_drawable" format="reference"/>

Then in your theme you should set drawable for this attr and now you can reference it anywhere you want.

<style name="Theme.MyDarkMaterialDesign" parent="Theme.MaterialComponents.NoActionBar">
        <item name="nav_bar_header_drawable">@drawable/side_nav_bar</item>

It works perfectly for API 19 and may be below (didnt test since I only need 19 API and above).

MockResources, Use getDrawable(int, android.content.res.Resources.Theme) instead. Return a drawable object associated with a particular resource ID. /** The <var>data</var> field holds an attribute resource * identifier (referencing an attribute in the current theme * style, not a resource entry). */ public static final int TYPE_ATTRIBUTE = 0x02;

You can't reference an attribute in an XML drawable below API 21.

Try to replace

<stroke android:color="?attr/colorPrimary" />


<stroke android:color="@color/colorPrimary" />

Resources, android.content.res. For more information about using resources, see the documentation about Theme, This class holds the current attribute values for a particular theme. Return a drawable object associated with a particular resource ID. and is not configured for the current screen (can not use dimension units,� Questions: When inflating my layout, I get this exception: E AndroidRuntime:

android.view.InflateException: Binary XML file line #0: Error inflating , It happens to ZenFone 2 device, Android 5.0 Im using this lib version 2.3.0 Fatal Caused by android.content.res. Resources$NotFoundException: Resource Don't use attribute / theme colors directly in color resource that may or Adding xml files with drawable causes error many times, sometimes� Customize your theme here. --> </style> </resources> According to developers guide we have to use NoActionBar theme to use toolbar as a action bar. Also extends your activity with ActionBarActivity. Edit Use AppCompatActivity instead of ActionBarActivity, It is deprecated.

core/java/android/content/res/, <p>For more information about using resources, see the documentation about <a current screen (can not use dimension units, does not change based on. * orientation public NotFoundException(String name, Exception cause) { @ param theme The theme used to style the drawable attributes, may be {@code null}. Android tutorial about implementing app slider menu using navigation drawer. An example of google + navigation drawer is explained with a customized list view with icon, title and a notification counter.

Resources$NotFoundException - android, InflateException: Binary XML file line #237: Error inflating class at android.view. loadDrawable( at android.content.res. The official answer - you can't use theme attributes for android:drawable or android:src attributes. This PR adds support for signing to Simplenote via your account. It supports creating a new Simplenote account if one didn&#39;t exist yet, or alternatively it will sign the user to a

  • can you post code of textview
  • where have you defined your colorPrimary?
  • Added textview xml to post
  • I defined colorPrimary in my theme as follows: <style name="DesignAppTheme" parent="AppTheme"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/designColorPrimary</item> ...
  • Theme attributes can't be used in XML drawables prior to Lollipop. You'll have to put your drawables that have theme attributes in drawable-v21/ folders, and use workarounds for older versions; e.g., separate drawables for each theme, setting the colors manually at runtime, etc.
  • I did this. Problem is that I got an exception. Seems like for my api level i have to restor to tricks described by Mike . M. in a comment above