How to Disable (Gray out) Google Pay Button


I'm using the PayButton from Google Pay library: com.google.android.gms:play-services-wallet:19.5.0.

I'm trying to disable the button (gray out effect) but there is no android:enabled on it, it only has android:saveEnabled.

I've tried following but didn't work:

fun PayButton.init() {
    isEnabled = false
    
    val buttonOptions = ButtonOptions.newBuilder().run {
        setButtonTheme(ButtonConstants.ButtonTheme.DARK)
        setButtonType(ButtonConstants.ButtonType.DONATE)
        setCornerRadius(16)
        setAllowedPaymentMethods("[]")
        build()
    }

    initialize(buttonOptions)
}
0
Feb 5 at 3:37 PM
User AvatarSam Chen
#android#google-pay

Accepted Answer

payButton.isClickable = false
payButton.alpha = 0.4f

try this: 

fun PayButton.initDisabled() {
    
    isClickable = false
    alpha = 0.4f

    val buttonOptions = ButtonOptions.newBuilder()
        .setButtonTheme(ButtonConstants.ButtonTheme.DARK)
        .setButtonType(ButtonConstants.ButtonType.DONATE)
        .setCornerRadius(16)
        .build()

    initialize(buttonOptions)
}
User AvatarLijith
Feb 5 at 3:53 PM
1