Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - how to set text for google+ signin button after authenticated

I have an android example using Google+ signin service. When start app, Google+ signin button appear with Login string.

How to set text Logout for Google+ signin button after connected and authenticated. Help me this issue.

like image 751
user3161772 Avatar asked Dec 07 '22 03:12

user3161772


2 Answers

After successful connection has been established by the GooglePlus client, the onConnected() callback is invoked.

So, all you need to do is change the text of the Button as soon as the user has been logged in.

@Override
    public void onConnected() {
        //called after successful connection
        setGooglePlusButtonText(signInButton, R.string.googleplus_signout);

    }


protected void setGooglePlusButtonText(SignInButton signInButton, String buttonText) {
    for (int i = 0; i < signInButton.getChildCount(); i++) {
        View v = signInButton.getChildAt(i);
        if (v instanceof TextView) {
            TextView mTextView = (TextView) v;
            mTextView.setText(buttonText);
            return;
        }
    }
}
like image 86
Swayam Avatar answered Dec 10 '22 13:12

Swayam


Use native Button for sign in/sign out with backgound - @drawable/common_signin_btn_text_dark

<Button
        android:id="@+id/gplus_sign_in_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/connect_with_gplus"
        android:background="@drawable/common_signin_btn_text_dark"
        android:textColor="@color/white"
       />
like image 30
T_V Avatar answered Dec 10 '22 11:12

T_V