Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize Google SignInButton In Android

I want to customise Google SignIn Button In Android. Currently I have a very basic default layout by using following code.

<com.google.android.gms.common.SignInButton
            android:id="@+id/sign_in_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

I am not satisfied with the current button layout. Is it possible to update the button text, background colour in the default button, Or Should I create full custom button layout?

Thank you.

ps: I am new to Android

like image 576
user1590595 Avatar asked May 16 '17 11:05

user1590595


People also ask

How do I customize my Google login button?

To create a Google Sign-In button with custom settings, add an element to contain the sign-in button to your sign-in page, write a function that calls signin2. render() with your style and scope settings, and include the https://apis.google.com/js/platform.js script with the query string onload=YOUR_RENDER_FUNCTION .

What is GoogleSignInOptions?

GoogleSignInOptions contains options used to configure the Auth.

What is Rc_sign_in?

Place where RC_SIGN_IN is used in the link, it gives another link to the complete class of that snippet and there it is defined that RC_SIGN_IN is an integer with value 9000.


3 Answers

Its very simple , you need to do this

<Button
 android:id="@+id/button"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:text="@string/common_signin_button_text_long" />

You can customize your button , but you will have to make sure you follow the guidelines. Edit: Check out this library custom signin button

If you want to do it yourself you can create a linear layout and add images.

like image 113
Dishonered Avatar answered Oct 18 '22 23:10

Dishonered


I think you have to do it pragmatically rather than xml something like this

public static void customizeGooglePlusButton(SignInButton signInButton) {
    for (int i = 0; i < signInButton.getChildCount(); i++)
    {
        View v = signInButton.getChildAt(i);

        if (v instanceof TextView)
        {
            TextView tv = (TextView) v;
            tv.setText("My Text");
            tv.setAllCaps(true);
            tv.setCompoundDrawablesWithIntrinsicBounds( R.drawable.smiley, 0, 0, 0);
            //here you can customize what you want  
            return;
        }
    }
}

another way but not that secure

TextView textView = (TextView) signInButton.getChildAt(0);
//Customize here
like image 43
sushant gosavi Avatar answered Oct 19 '22 01:10

sushant gosavi


Basically, Google SignInButton is a FrameLayout you can customize it as you want but need some dynamic tweaks.

XML part adding custom background to the frame layout, make your own.

  <com.google.android.gms.common.SignInButton
                    android:id="@+id/google_signIn"
                    android:layout_width="match_parent"
                    android:background="@drawable/google_bottun_bg"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="5dp">

                // google image logo
                <ImageView android:layout_width="16dp"
                           android:layout_height="16dp"
                           android:layout_gravity="center_vertical"
                           android:layout_marginLeft="12dp"
                           app:srcCompat="@drawable/ic_gmail"/>
  </com.google.android.gms.common.SignInButton>
  1. inside FrameLayout we have a textView so you can redesign text view as needed

      fun reDesignGoogleButton(signInButton: SignInButton, buttonText: String) {
             for (i in 0 until signInButton.childCount) {
              val v = signInButton.getChildAt(i)
              if (v is TextView) {
               v.text = buttonText //setup your text here
               v.setBackgroundResource(android.R.color.transparent) //setting transparent color that will hide google image and white background
               v.setTextColor(resources.getColor(R.color.white)) // text color here
               v.typeface = Typeface.DEFAULT_BOLD // even typeface 
               return
                 }
              }
           } 
    

    Happy Coding

see the results

like image 1
Salman_Zach Avatar answered Oct 18 '22 23:10

Salman_Zach