如何获取默认的Google+按钮到Android应用程序

时间:2016-01-14 15:02:15

标签: android google-signin google-plus-signin

您好我正在尝试在Android中学习Google登录功能。我按照预期做了这个并正常工作。我正在按照本教程。 http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/

此处显示的是默认的Google登录按钮,而不是Google+红色按钮。

<com.google.android.gms.common.SignInButton
    android:id="@+id/btn_sign_in"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"/>

default sign in

问题 如何获取Google+按钮,如下所示。 goole plus sign in

1 个答案:

答案 0 :(得分:1)

您可以在this Google's sample code内找到以下内容,从第67行到第78行

        // [START customize_button]
        // Customize sign-in button. The sign-in button can be displayed in
        // multiple sizes and color schemes. It can also be contextually
        // rendered based on the requested scopes. For example. a red button may
        // be displayed when Google+ scopes are requested, but a white button
        // may be displayed when only basic profile is requested. Try adding the
        // Scopes.PLUS_LOGIN scope to the GoogleSignInOptions to see the
        // difference.
        SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
        signInButton.setSize(SignInButton.SIZE_STANDARD);
        signInButton.setScopes(gso.getScopeArray());
        // [END customize_button]

因此,您可以使用以下内容:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(Scopes.PLUS_LOGIN))                
                .requestEmail()
                .build();

希望它有所帮助!