How to make a circular ripple on a button when it's being clicked?

后端 未结 12 2202
一个人的身影
一个人的身影 2021-01-29 18:59

Background

On the dialer app of Android, when you start searching for something, and you click the arrow button on the left of the EditText, you get a circular ripple

12条回答
  •  独厮守ぢ
    2021-01-29 19:26

    In Kotlin / Java you can do the following

    fun View.applyCircularRippleEffect() {
        val backgroundResId = context.getResource(android.R.attr.actionBarItemBackground)
    
        if (backgroundResId != 0) {
            setBackgroundResource(backgroundResId)
            isClickable = true
            isFocusable = true
        }
    }
    
    // getResource extension
    fun Context.getResource(resourceId: Int): Int {
        val out = TypedValue()
        theme.resolveAttribute(resourceId, out, true)
    
        return out.resourceId
    }
    

提交回复
热议问题