Home > Blockchain >  How to create Google signup button in android using kotlin
How to create Google signup button in android using kotlin

Time:02-02

I am using jetcompose android with kotlin and i am trying to create a google signup/signin button. I could only create the SignInButton object. But i didnt find anyway on how to render it.

val signupButton = SignInButton(LocalContext.current)

Package from where i imported SigninButton

com.google.android.gms.common.SignInButton

I am trying to render the signupbutton but unable to render using the above code

CodePudding user response:

The com.google.android.gms.common.SignInButton is a View, not a Composable so it won't be rendered inside of a Composable context. To render Views that are commonly used in XML layouts you should use AndroidView into a Composable context and put the View inside it.

AndroidView(
            factory = { ctx ->
                SignInButton(ctx).apply {
                    setOnClickListener {
                        //Handle on click
                        Toast.makeText(ctx, "On SignInButton clicked!", Toast.LENGTH_SHORT)
                            .show()
                    }
                }
            },
            modifier = Modifier.fillMaxWidth()
        )
  • Related