Android: getting Resources$NotFoundException for abc_ic_ab_back_material

后端 未结 7 2009
终归单人心
终归单人心 2020-12-19 02:31

I\'m getting a Resources$notfoundexception on older (pre-L) devices. I\'m including the full stacktrace below.

My version of the support library is the latest (24.1

相关标签:
7条回答
  • 2020-12-19 03:07

    Instead of:

    ContextCompat.getdrawable()
    

    Try using:

    AppCompatDrawableManager.get().getDrawable() 
    
    0 讨论(0)
  • 2020-12-19 03:08

    Another solution,
    in addition to AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
    is to wrap your vector drawable into another drawable:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/ic_your_vector"/>
    </selector>
    

    Might be useful when you use as a drawable for a TextView (i.e. DrawableLeft)

    0 讨论(0)
  • 2020-12-19 03:12

    Accepted answer is not covered all cases. It will not work on Android 4.0.3/4.1.1/4.1.2 platform with 25.x.x support library. The right way to fix problem with abc_ic_ab_back_material.xml is to override homeAsUpIndicator attribute in your theme. For example, my theme is inherited from Theme.AppCompat.Light.NoActionBar. As for value of mentioned attribute, you can use @drawable/abc_ic_ab_back_mtrl_am_alpha or your custom 'back' drawable.

    0 讨论(0)
  • 2020-12-19 03:13

    Please make sure you are using AppCompatActivity instead Activity. If you're using AppCompat's theme, then you also need to use it's Activity.

    0 讨论(0)
  • 2020-12-19 03:13

    private resources its treated differently at compile time and runtime..to fix I usually take the offending private resource and backport it to my app in my res files

    0 讨论(0)
  • 2020-12-19 03:23

    The answer to this turned out to be buried at the bottom of this guide:

    https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.xucjbsts0

    It turns out that all you need to add this line in at the beginning of the activity that will use the resource:

    static {
            AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
        }
    
    0 讨论(0)
提交回复
热议问题