How do I make a Spinner's “disabled” state look disabled?

后端 未结 13 1577
傲寒
傲寒 2020-12-09 03:00

When I disable my Spinner it looks almost exactly like it did prior to being disabled, i.e.

Before

13条回答
  •  一个人的身影
    2020-12-09 03:14

    For future reference, if you're using Kotlin, you can make use of extension functions, and provide a custom behaviour for disabled elements:

    fun Spinner.forceEnabled(isEnabled : Boolean){
        setEnabled(isEnabled)
        getChildAt(0)?.let{ childView ->
            childView.alpha = if (this.isEnabled) 1.0f else 0.33f
        }
        invalidate()
    }
    
    someSpinner.forceEnabled(true)
    

    This will allow to set custom properties to spinner children views, as the spinner is being disabled, without need for subclassing. Be cautious, as extension functions are resolved statically!

提交回复
热议问题