LoginSignup
56
50

More than 5 years have passed since last update.

API22を含める場合のDrawableリソースへのアクセス

Last updated at Posted at 2015-07-07

targetSdkVersion で API level 22 を指定している場合、これまで使用していたResources#getDrawable(int) はdeprecatedと言われ取り消し線が引かれてしまいます。

もしAPI level 22を含めるアプリを作る場合はSupportLibraryを使い、以下のように変更しておいた方が良さそうです。

変更前

Drawable drawable = getResources().getDrawable(R.drawable.hoge);

変更後

Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.hoge, null);

該当するリファレンスは、以下となります。
- Resources#getDrawable(int)
- ResourcesCompat

56
50
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
56
50