我想在我的一个布局中使用com.google.android.gms.common.SignInButton
,但遗憾的是,没有任何有价值的理由,按钮内的文字并不想成为中心。
以下是它的外观:
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>
编辑:
即使活动完全空了,这个按钮也没有正确显示......我疯了吗?
有人已经遇到过这个问题吗?
谢谢
答案 0 :(得分:3)
compile 'com.google.android.gms:play-services-auth:9.8.0'
这个Google登录按钮实际上并没有执行任何特殊功能,但是有法律限制,因为你想使用相同的背景作为替代,你可以选择自定义登录按钮将背景保存为image。
用于对用户进行身份验证的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" />
答案 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"