BruceLee BruceLee - 5 months ago 20
Android Question

How to change SignInButton's text?

In my app, I use SignInButton, the text on it is default "登录", like this:
login sample

But I want to change the default text to "Google login". I refer to the official tutorial, however, find no meaningful answer. I hope someone can help, Thanks a lot.

Answer

As SignInButton extends FrameLayout, So it has no function to setText. I think you can use below code to realize your goal:

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;
    }
} }

Another way, try to write your custom login button, which is an easy case, as @NIPHIN says. Hope this answer will solver your question.

Comments