I am trying to use the Notification.Builder.setLargeIcon(bitmap)
that takes a bitmap image. I have the image I want to use in my drawable folder so how do I convert that to bitmap?
183
votes
6 Answers
421
votes
46
votes
Drawable myDrawable = getResources().getDrawable(R.drawable.logo);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
Since API 22 getResources().getDrawable()
is deprecated, so we can use following solution.
Drawable vectorDrawable = VectorDrawableCompat.create(getResources(), R.drawable.logo, getContext().getTheme());
Bitmap myLogo = ((BitmapDrawable) vectorDrawable).getBitmap();
13
votes
9
votes
7
votes
0
votes
In res/drawable
folder,
1. Create a new Drawable Resources
.
2. Input file name.
A new file will be created inside the res/drawable
folder.
Replace this code inside the newly created file and replace ic_action_back
with your drawable file name.
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_action_back"
android:tint="@color/color_primary_text" />
Now, you can use it with Resource ID, R.id.filename
.