编程语言
首页 > 编程语言> > 如何获得Android应用程序的默认谷歌按钮

如何获得Android应用程序的默认谷歌按钮

作者:互联网

您好我正在尝试在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

解决方法:

您可以在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();

希望能帮助到你!

标签:android,google-signin,google-plus-signin
来源: https://codeday.me/bug/20190706/1397039.html