How to create google plus button with custom layout in Android?

I want to create my own layout for my google plus button, any ideas? I tried to call the google plus button OnClickEvent (it doesn't work) and I tried to change the background image. Source:

           <com.google.android.gms.plus.PlusOneButton
            xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
            android:id="@+id/plus_one_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            plus:size="standard"
            plus:annotation="inline"/>

    holder.mPlusOneButton = (PlusOneButton) holder.content.findViewById(R.id.plus_one_button);
    holder.mPlusOneButton.initialize("http://www.xxx.xx/", 0);

      

+2


source to share


1 answer


  • Add custom button to layout
  • Set OnClickListener

    to custom button
  • Use PlusClient

    as described here to handle the login procedure

As an example, I can provide my controller class to handle Google Plus login:



public class GooglePlusLoginController implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener {

    public static final int REQUEST_CODE_SIGN_IN = 100;

    private PlusClient googlePlusClient;
    private ConnectionResult connectionResult;
    private Activity activity;

    public GooglePlusLoginController(Activity activity) {
        this.activity = activity;


        googlePlusClient = new PlusClient.Builder(activity, this, this)
                .setActions("http://schemas.google.com/AddActivity")
                .setScopes(Scopes.PLUS_LOGIN) // Space separated list of scopes
                .build();
        googlePlusClient.connect();
    }

    // call this method in your click handler
    public void login() {
        try {
            connectionResult.startResolutionForResult(activity, REQUEST_CODE_SIGN_IN);
        } catch (IntentSender.SendIntentException e) {
            googlePlusClient.connect();
        }
    }

    // call this method in your activity onActivityResult
    public void onActivityResult() {
        if(!googlePlusClient.isConnected() && !googlePlusClient.isConnecting()) {
            googlePlusClient.connect();
        }
    }

    @Override
    public void onConnected(Bundle bundle) {
        // connected, you can now get user data from
        // googlePlusClient.getCurrentPerson()
    }

    @Override
    public void onDisconnected() {
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        connectionResult = result;
    }

    private void logout() {
        if(googlePlusClient.isConnected()) {
            googlePlusClient.clearDefaultAccount();
            googlePlusClient.disconnect();
            googlePlusClient.connect();
        }
    }
}

      

+2


source







All Articles