安卓谷歌加登录按钮样式

8

我需要在Android中使用Google+登录,需要长样式的按钮。

根据品牌指南,该按钮有不同的样式,如长、中等、短等。

我已经通过示例应用程序获取了中等样式的按钮,但我想要长样式的按钮。

这是我的按钮 `

   <com.google.android.gms.common.SignInButton
        android:id="@+id/sign_in_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:visibility="visible" />

`


请在此处发布您的代码。 - dipali
我已经添加了按钮的代码,但我不知道如何更改它的样式。提前致谢。 - iFunDroid
但是为什么你要改变风格呢? - dipali
如果您能在这里提供帮助,我们将不胜感激。 - iFunDroid
4个回答

20

根据网站描述,有三种不同尺寸的按钮:

  1. 仅图标 = SignInButton.SIZE_ICON_ONLY
  2. 普通按钮 = SignInButton.SIZE_STANDARD
  3. 宽按钮 = SignInButton.SIZE_WIDE

您可以像这样使用它。

gSignInButton = (SignInButton) findViewById(R.id.sign_in_button);
gSignInButton.setOnClickListener(this);
gSignInButton.setEnabled(true);
gSignInButton.setSize(SignInButton.SIZE_WIDE);// wide button style

1
我想在xml中更改按钮大小,而不是在编码中进行更改,因为我正在为不同大小设计屏幕,所以如果我在代码中进行更改,它将影响所有屏幕。请告诉我如何在xml编码中实现。 - Niranjan

12

您可以通过添加并使用app命名空间(作为自定义属性)来使用XML完成此操作:

<com.google.android.gms.common.SignInButton
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/sign_in_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      app:buttonSize="wide"
      app:colorScheme="dark"
      />

可能的属性值包括:

  • buttonSize: "wide", "icon_only"或默认值"standard"
  • colorScheme: "dark", "light"和默认值"auto"

1
你是怎么发现这个应用程序属性中可用的不同值的? - Pol
1
我主要是通过常量名称的推断和尝试来获取它们:https://developers.google.com/android/reference/com/google/android/gms/common/SignInButton#constant-summary。但我发现了一种更严谨的方法,从库aar源文件中获取:https://github.com/dandar3/android-google-play-services-base/blob/master/res/values/values.xml。 - Jérémy Reynaud

3
您可以使用登录按钮的setSize方法来更新大小。
例如,在我的活动的onCreate方法中:
    mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);
    mSignInButton.setOnClickListener(this);
    mSignInButton.setSize(SignInButton.SIZE_WIDE);

将会把“登录”按钮变成宽按钮。

您也可以使用任何带有品牌标识的按钮,只需使用一个按钮,然后将该活动用作按钮的单击处理程序即可。


0
将此按钮的可见性设置为View.GONE,制作自定义按钮并从您的按钮发送onclick事件到SignInButton.performClick()。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接