More AndroidView fun! I want to get my AndroidVie...
# compose-android
c
More AndroidView fun! I want to get my AndroidView to ripple on click or long click
Copy code
AndroidView(
    factory = { context ->
      FrameLayout((context).apply {
     setOnClickListener {  }
this doesn't give me a ripple
Old wisdom tells me I should set background of my view to
Copy code
"?selectableItemBackground"
which you can apparently do programatically via
Copy code
val outValue = TypedValue()
context.theme.resolveAttribute(
    android.R.attr.selectableItemBackground,
    outValue,
    true
)
setBackgroundResource(outValue.resourceId)
still no dice though... 😭
f
Not at my desk so can't check, but could you move the click listener to the AndroidView via its Modifier? I seem to recall you may need a solid background for the ripple, but not 100% sure
c
let me try that. didn't know that AndroidView had a modifier param 🤦
nope. no dice. 🤯
s
Try constructing RippleDrawable as a background maybe? Ripples are weeeeird
f
I have a ripple with this
Copy code
AndroidView(
    modifier = Modifier.clickable {  },
    factory = { context ->
        FrameLayout((context)).apply {
        }
    }
)
this also works
Copy code
AndroidView(
    factory = { context ->
        FrameLayout((context)).apply {
            val typedValue = TypedValue()
            context.theme.resolveAttribute(
                R.attr.selectableItemBackground,
                typedValue,
                true
            )
            setBackgroundResource(typedValue.resourceId)
            setOnClickListener {  }
        }
    }
)
in the 2nd case, the ripple is less noticeable though
c
Weird. Maybe there's something else in my setup that's the culprit. I'll try to work backwards from here. Thanks all!
z
Random but compose ripples don't show on Android 14 b3.
c
thanks, im specifically not running this on my beta device for this reason. 😅