Android - Google SignInButton文字不居中

时间:2017-02-10 01:58:28

标签: android google-signin

我想在我的一个布局中使用com.google.android.gms.common.SignInButton,但遗憾的是,没有任何有价值的理由,按钮内的文字并不想成为中心。

以下是它的外观:

enter image description here

xml非常简单,我尝试使用margin / padding / gravity / ...但没有任何方法可以使文本居中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/toolbar" />

    <com.google.android.gms.common.SignInButton
        android:id="@+id/button_google_sign_in"
        android:layout_width="200dp"
        android:layout_height="60dp"
        android:layout_centerInParent="true" />

</RelativeLayout>

编辑:

即使活动完全空了,这个按钮也没有正确显示......我疯了吗?

enter image description here

有人已经遇到过这个问题吗?

谢谢

4 个答案:

答案 0 :(得分:3)

  • 检查您的Google Play服务版本, 我希望您使用document
  • 中提到的compile 'com.google.android.gms:play-services-auth:9.8.0'
  • 检查您的附加内容@ SDK Manager
  • 是否有任何播放服务更新
  • 要确认问题出在您安装的任何东西上,您可以在另一台PC上运行项目
  • 最后,如果您无法解决问题,请选择Customizing the Sign-In Button

这个Google登录按钮实际上并没有执行任何特殊功能,但是有法律限制,因为你想使用相同的背景作为替代,你可以选择自定义登录按钮将背景保存为image

enter image description here

  

用于对用户进行身份验证的Google登录按钮。请注意这一点   class 仅处理按钮的视觉方面。为了   触发一个动作,使用注册一个监听器   setOnClickListener(OnClickListener)

https://developers.google.com/android/reference/com/google/android/gms/common/SignInButton

答案 1 :(得分:0)

使用此

  compile 'com.google.android.gms:play-services-auth:9.8.0'

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<com.google.android.gms.common.SignInButton
    android:id="@+id/button_google_sign_in"
    android:layout_width="200dp"
    android:layout_height="60dp"
    android:layout_centerInParent="true" />

enter image description here

答案 2 :(得分:0)

我知道这是一个较晚的答案,但对于将来的看法。

SignInButton signInButton = ((SignInButton) findViewById(R.id.btn_sign_in));
    for (int i = 0; i < signInButton.getChildCount(); i++) {
     View v = signInButton.getChildAt(i);
 if (v instanceof TextView) {
            TextView tv = (TextView) v;
            tv.setPadding(0, 8, 0, 0);
            return;
        }
    }

答案 3 :(得分:-1)

  <com.google.android.gms.common.SignInButton
                android:id="@+id/sign_in_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center"
                />


Use android:layout_gravity="center"