Android Google加登录按钮样式

时间:2014-01-10 11:15:07

标签: android google-plus android-styles

我需要Android中的google + signin的长样式按钮。

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

我在示例应用程序的帮助下获得了中等样式按钮,但我想要长样式按钮。

这是我的按钮`

   <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" />

`

4 个答案:

答案 0 :(得分:18)

正如网站所描述的那样,有3个大小的按钮

  1. 仅限图标= SignInButton.SIZE_ICON_ONLY
  2. 正常按钮= SignInButton.SIZE_STANDARD
  3. 宽按钮= SignInButton.SIZE_WIDE
  4. 你可以这样使用它。

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

答案 1 :(得分:9)

你可以通过添加&amp;来实现XML。使用app命名空间(因为它们是自定义属性):

<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" or "standard"(默认)
  • colorScheme:"dark", "light" & "auto"(默认)

答案 2 :(得分:3)

您可以使用“登录”按钮的setSize方法更新尺寸。

例如,在我的活动的onCreate方法中:

    mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);
    mSignInButton.setOnClickListener(this);
    mSignInButton.setSize(SignInButton.SIZE_WIDE);

会将登录按钮更改为宽。

您也可以使用任意按钮,只需使用按钮,然后将活动用作按钮的点击处理程序。

答案 3 :(得分:0)

只需将此按钮的可见性设置为View.GONE,创建您的自定义按钮并将onclick事件从您的按钮发送到SignInButton.performClick()