谷歌加上看起来像谷歌登录按钮android

时间:2016-01-29 03:08:37

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

我有一个项目,我喜欢使用google plus登录。 与Google指南“在控制台中创建并打开google plus api”一样 https://developers.google.com/identity/sign-in/android/start-integrating

如图所示

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

并在我的登录类中添加

SignInButton signInButton = (SignInButton) findViewById(R.id.btn_signup_gmail);
    signInButton.setSize(SignInButton.SIZE_WIDE);
    signInButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            signIn();
        }
    });

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(new Scope (Scopes.PLUS_LOGIN))
            .addScope(new Scope(Scopes.PLUS_ME))
            .build();

问题是google plus按钮显示如下  enter image description here

1 个答案:

答案 0 :(得分:1)

您可以改用以下内容:

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

然后,

SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_STANDARD);
signInButton.setScopes(gso.getScopeArray());