Layout Google Sign In Button - Android

前端 未结 3 558
难免孤独
难免孤独 2021-01-03 04:54

I\'m searching everywhere and not finding what I want, I\'m starting to think that this is impossible.

Here\'s the question: I have a google button for sign in, it\'

相关标签:
3条回答
  • 2021-01-03 05:01

    You can create your own button and use XML tag android:drawableLeft="@drawable\file" to show any image on button.

    0 讨论(0)
  • 2021-01-03 05:05

    I have your question solution. I tried this always for custom SignIn Button for google plus.

    Try this it is tested by me.

    Here is the Code.

    xml layout

    <com.google.android.gms.common.SignInButton
        android:id="@+id/google_button"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"
        android:text="Text"
        android:layout_alignParentTop="true"
        android:layout_margin="10dp"
        android:textSize="18sp" />
    

    Method for customisation

    private void googleBtnUi() {
        // TODO Auto-generated method stub
    
        SignInButton googleButton = (SignInButton) findViewById(R.id.google_button);
        googleButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
    
            }
        });
    
        for (int i = 0; i < googleButton.getChildCount(); i++) {
            View v = googleButton.getChildAt(i);
    
            if (v instanceof TextView)
            {
                TextView tv = (TextView) v;
                tv.setTextSize(14);
                tv.setTypeface(null, Typeface.NORMAL);
                tv.setText("My Text");
                tv.setTextColor(Color.parseColor("#FFFFFF"));
                tv.setBackgroundDrawable(getResources().getDrawable(
                        R.drawable.ic_launcher));
                tv.setSingleLine(true);
                tv.setPadding(15, 15, 15, 15);
    
                return;
            }
        }
    }
    

    Edit

    Add this code before return in method googleBtnUi()

    ViewGroup.LayoutParams params = tv.getLayoutParams();
    params.width = 100;
    params.height = 70;
    tv.setLayoutParams(params);
    
    0 讨论(0)
  • 2021-01-03 05:20

    There's no need to use Google Sign-In button, if it doesn't fit in your layout. You can simply create your own Button with your own design and in OnClick method just create Google sign in intent.

    Button myGoogleBtn = (Button) findViewById(R.id.loginGoogle);
    myGoogleBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           Intent signInIntent = mGoogleSignInClient.getSignInIntent();
           startActivityForResult(signInIntent, RC_SIGN_IN); 
        }
    });
    
    0 讨论(0)
提交回复
热议问题