Has anyone used 9patch images with compose? Can’t ...
# compose
d
Has anyone used 9patch images with compose? Can’t wrap my head around how to make it work. How can I set a 9patch as a background of, say, a
Box
?
🤘 1
@Sergey Y. sorry for tagging you here. I just saw your thread where you were trying to figure out how to use
Drawable
-like backgrounds with buttons. Was just wondering if you were able to achieve what you needed?
s
Hi. Well, I have ditched that idea and set simple gradient on the background. There will be an API for hoisting view state(pressed, selected, etc). Using that state it will be easy to provide custome background drawable to a button.
d
I see. Seems like I’ll have to do this with standard android views and wrap it with compose functions for now. Thanks for the reply tho, appreciate it!
n
Just leaving an answer here just in case someone like search for it:
Copy code
val context = LocalContext.current
Image(
    rememberDrawablePainter(
        drawable = ContextCompat.getDrawable(context, R.drawable.your9patch)
    ),
    contentDescription = null,
    // Modifier.fillMaxWidth().height(150.dp)
)
414 Views