我试图使用Notification.Builder.setLargeIcon(bitmap)
带有位图图像.我有我想在可绘制文件夹中使用的图像,那么如何将其转换为位图?
poi*_*oae 396
你可能是的意思Notification.Builder.setLargeIcon(Bitmap)
,对吗?:)
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.large_icon);
notBuilder.setLargeIcon(largeIcon);
Run Code Online (Sandbox Code Playgroud)
这是将资源图像转换为Android Bitmap
的一种很好的方法.
And*_*dyW 43
Drawable myDrawable = getResources().getDrawable(R.drawable.logo);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
Run Code Online (Sandbox Code Playgroud)
由于API 22 getResources().getDrawable()
已弃用,因此我们可以使用以下解决方案.
Drawable vectorDrawable = VectorDrawableCompat.create(getResources(), R.drawable.logo, getContext().getTheme());
Bitmap myLogo = ((BitmapDrawable) vectorDrawable).getBitmap();
Run Code Online (Sandbox Code Playgroud)
aro*_*ero 13
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.my_drawable);
Run Code Online (Sandbox Code Playgroud)
Context
可以是你当前的Activity
.
这是另一种将Drawable资源转换为android中的Bitmap的方法:
Drawable drawable = getResources().getDrawable(R.drawable.input);
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
Run Code Online (Sandbox Code Playgroud)
首先创建位图图像
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.image);
Run Code Online (Sandbox Code Playgroud)
现在在Notification Builder Icon中设置位图....
Notification.Builder.setLargeIcon(bmp);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
209064 次 |
最近记录: |