LoginSignup
1
1

More than 5 years have passed since last update.

Android Support Library 23.3 で Resources$NotFoundException

Posted at

API Level 21 Lollipop以下の端末でvector画像を使用している場合に Support Library 23.3 にバージョンを上げると Resources$NotFoundException が発生します。
こちらは 23.3 から発生するようで、23.2 と 23.3 の差異については下記の記事で @androhi さんが解説してくださっています。
Support Vector Drawableのバージョン間差異について

解決方法

こちらの記事の下記コメントや

You can always just remove vectorDrawables.useSupportLibrary = true from your build.gradle to make the build system generate PNGs at compile time. Your built APK will be bigger, but you won't need to spend a ton of time redoing all your assets.

こちらの回答にもある通り

build.gradle の

vectorDrawables.useSupportLibrary = true

を削除することで正常に動くようになります。(よって自動png生成が有効になり容量は増えてしまう?未検証)

vector.xml の android:fillColor が効かない

上記のコードを削除することで正常に動くようだったのですが、自分の開発しているアプリでは android:fillColor が効かなくなってしまいました。
こちらを解決するために取った方法は2つあります。

  • 直接色コードを指定する
<vector>
  <path android:fillColor="#4FC2F7" />
</vector>
  • DrawableCompat.setTint を使う
Drawable icon = ContextCompat.getDrawable(context, R.drawable.icon);
DrawableCompat.setTint(DrawableCompat.wrap(icon), ContextCompat.getColor(context, R.color.primary_color));
// DrawableをDrawableCompat.wrap(icon)で包むのを忘れない
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1