このページにある答えに基づいて、私が書いたこのクラスを使用w.donahue
できます。
import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.google.android.gms.common.SignInButton;
public class GoogleLoginButton extends FrameLayout implements View.OnClickListener{
private SignInButton signInButton;
private OnClickListener onClickListener;
public GoogleLoginButton(Context context) {
super(context);
init();
}
public GoogleLoginButton(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public GoogleLoginButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
signInButton = new SignInButton(getContext());
signInButton.setSize(SignInButton.SIZE_STANDARD);
setGooglePlusButtonText(signInButton, "Test");
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
addView(signInButton, params);
}
protected void setGooglePlusButtonText(SignInButton signInButton, String buttonText) {
// Find the TextView that is inside of the SignInButton and set its text
for (int i = 0; i < signInButton.getChildCount(); i++) {
View v = signInButton.getChildAt(i);
if (v instanceof TextView) {
TextView tv = (TextView) v;
tv.setText(buttonText);
return;
}
}
}
@Override
public void setOnClickListener(OnClickListener onClickListener) {
this.onClickListener = onClickListener;
if(this.signInButton != null) {
this.signInButton.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
if(this.onClickListener != null && v == this.signInButton) {
this.onClickListener.onClick(this);
}
}
}