Câu trả lời:
Bạn có thể có nghĩa Notification.Builder.setLargeIcon(Bitmap), phải không? :)
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.large_icon);
notBuilder.setLargeIcon(largeIcon);
Đây là một phương pháp tuyệt vời để chuyển đổi hình ảnh tài nguyên sang Android Bitmap.
... E/CommitToConfigurationOperation: Malformed snapshot token (size): ... E/NotificationService: Not posting notification with icon==0: Notification(pri=0 contentView=null vibrate=null sound=content://settings/system/notification_sound defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE) ... E/NotificationService: WARNING: In a future release this will crash the app:...
Drawable myDrawable = getResources().getDrawable(R.drawable.logo);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
Vì API 22 getResources().getDrawable()không được dùng nữa, vì vậy chúng tôi có thể sử dụng giải pháp sau.
Drawable vectorDrawable = VectorDrawableCompat.create(getResources(), R.drawable.logo, getContext().getTheme());
Bitmap myLogo = ((BitmapDrawable) vectorDrawable).getBitmap();
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.my_drawable);
Contextcó thể là hiện tại của bạn Activity.
Đây là một cách khác để chuyển đổi tài nguyên Drawable thành Bitmap trong Android:
Drawable drawable = getResources().getDrawable(R.drawable.input);
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
Tạo hình ảnh Bitmap đầu tiên
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.image);
bây giờ đặt bitmap trong Biểu tượng trình tạo thông báo ....
Notification.Builder.setLargeIcon(bmp);
Trong res/drawablethư mục,
1. Tạo một cái mới Drawable Resources.
2. Tên tệp đầu vào.
Một tập tin mới sẽ được tạo bên trong res/drawable thư mục.
Thay thế mã này bên trong tệp vừa tạo và thay thế ic_action_backbằng tên tệp có thể vẽ của bạn.
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_action_back"
android:tint="@color/color_primary_text" />
Bây giờ, bạn có thể sử dụng nó với Resource ID , R.id.filename.