Can I edit the text of sign in button on Google? Can I edit the text of sign in button on Google? android android

Can I edit the text of sign in button on Google?


Here is the technique that I used:

protected void setGooglePlusButtonText(SignInButton signInButton, String buttonText) {    // Find the TextView that is inside of the SignInButton and set its text    for (int i = 0; i < signInButton.getChildCount(); i++) {        View v = signInButton.getChildAt(i);        if (v instanceof TextView) {            TextView tv = (TextView) v;            tv.setText(buttonText);            return;        }    }}


Here is the easiest way that I used:

    TextView textView = (TextView) signInButton.getChildAt(0);    textView.setText("your_text_xyz");


Problem:

Other answers have mentioned a workaround. The underlying implementation of the button may change any time which would cause the code to break. I felt uncomfortable trying to use the hacks. For a clean solution, you would think that setting android:text on the com.google.android.gms.common.SignInButton in your layout file would do the trick. However it turns out that that attribute is not available for SignInButton.

Aim

Google's guidelines

From documentation, Google suggests creating a custom button as mentioned on Customizing the Sign-In Button [Archived now. See the archived page here]. It suggests using the branding guidelines as mentioned at Sign-In Branding Guidelines. This includes using the given custom icons and images in the button, setting specific text size, paddings and other do's and don'ts for the logo.

Clean Solution:

Doing as per Google's suggestion involves some custom work. I was willing to do that but wanted to create something reusable, so that others won't have to go through this again. That's why I wrote a quick small (4KB) library does that. Feel free to contribute to it for everyone's benefit if you find issues.

  • Step 1: Add the following to your app module level build.gradle file:

    dependencies {    implementation 'com.shobhitpuri.custombuttons:google-signin:1.1.0'}
  • Step 2: In your XML Layout, have the following:

    <RelativeLayout    ...    xmlns:app="http://schemas.android.com/apk/res-auto">    <com.shobhitpuri.custombuttons.GoogleSignInButton        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerInParent="true"        android:text="@string/google_sign_up"        app:isDarkTheme="true" /></RelativeLayout>

Usage

  • android:text="{string}": As usual to set the text on the button.

  • app:isDarkTheme="{Boolean}": To switch between blue theme and white theme for the button. The library handles changing of text color and background color. It also handles the change of color on button press or button clicks.

Source:

Hope it helps someone.