Issue
In Jetpack Compose, who can tell me is there a way to assign a Drawable Object to the Image compose view?
I took the apps installed on an Android device. I get an icon with the type that is Drawable and I want to use it in Image
val icon: Drawable = packageInfor.applicationInfo.loadIcon(packageManager)
I found there are 3 functions that can assign images
- From Painter (IdRes)
- From ImageBitmap
- From ImageVector
From all that I don't know how to assign a Drawable instance.
Solution
After all, I found a simple solution with Accompanist. Thanks to @Sinner of the System for suggesting to me.
Adding this dependency to the app gradle.
implementation "com.google.accompanist:accompanist-drawablepainter:<version>" //0.16.0
Using:
Image(
painter = rememberDrawablePainter(drawable = drawable),
contentDescription = "content description",
)
Check out: Drawable Painter¶
Answered By - Wilson Tran
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.