12

默认的 Facebook LoginButton 对象和 Google SignIn 按钮对象的外观完全不同,它们不适合我现有的布局。据我所知,这些对象不是我可以在不更改库本身的情况下修改的资产(我假设这些组件也是开源的)

人们如何处理这个问题?我已经看到应用程序对使用自己的自定义按钮的两个应用程序都有登录选项,但在我的实现中,我使用的是那些在点击时自动调用其各自库的给定对象。

我当然可以潜得更深,但如果我这样做,我觉得我正在重新发明不那么明显的轮子

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

这个对象显然不是一个按钮,我还没有检查它是否真的是一个按钮。

我需要为 Google+ 和 Facebook 登录按钮使用不同的资产。

是)我有的

我喜欢的一个 android 示例(Duolingo 应用程序)

编辑:经过一些非常简单的布局调整后,这是结果(在横向模式下,只是为了说明问题)

这些按钮仍然非常不同,我需要一个仍然可以访问正确方法的不同资产。多亏了这些例子,我有点知道如何用 Facebook 来做,但谷歌登录现在对我来说非常神秘

4

4 回答 4

12

要更改 Facebook 按钮上的文本,请使用:

fb:login_text="Put your login text here"
fb:logout_text="Put your logout text here"

您还需要将其添加到按钮中:

xmlns:fb="http://schemas.android.com/apk/res-auto"

像这样:

<com.facebook.widget.LoginButton
        xmlns:fb="http://schemas.android.com/apk/res-auto"
        android:id="@+id/login_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="0dp"
        fb:login_text="Sign in with Facebook"
        />
于 2013-09-30T05:23:36.180 回答
3

试试这个:将此方法添加到您的活动中:

protected void setGooglePlusButtonText(SignInButton signInButton, String buttonText) {
        for (int i = 0; i < signInButton.getChildCount(); i++) {
            View v = signInButton.getChildAt(i);

            if (v instanceof TextView) {
                TextView tv = (TextView) v;
                tv.setTextSize(15);
                tv.setTypeface(null, Typeface.NORMAL);
                tv.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
                tv.setText(buttonText);
                return;
            }
        }
    }

在onCreateMethod中添加以下行 (您在其中初始化了 id):

setGooglePlusButtonText(btnSignIn, getString(R.string.common_signin_button_text_long));
于 2015-03-18T12:22:30.493 回答
1

按钮的样式并不完全相同 - 拐角处的不同曲线和阴影的使用。所以不可能让它们看起来完全一样。我能得到的最接近的是制作一个精确宽度为 215dip 的垂直线性布局 - 并将按钮的宽度设置为 match_parent:

在此处输入图像描述

这使用了以下 layout.xml:

<LinearLayout
    android:layout_width="215dip"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:orientation="vertical" >

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

<com.facebook.widget.LoginButton
    android:id="@+id/authButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

使用 Google+ 按钮,您可以简单地使用自己的资产 - com.google.android.gms.common.SignInButton行为android.widget.Button与您以正常方式注册 onClick 处理程序相同。创建资产时,请务必遵循 Google 的品牌指南:

https://developers.google.com/+/branding-guidelines

但是请注意,如果您以多种语言实现自己的按钮,Google+ 按钮确实提供了您需要自己创建的翻译。

于 2013-05-31T10:56:08.950 回答
0

使用最新的 sdk,两个按钮看起来都很相似。代码和结果如下所述。

第 1 步:构建.gradle

编译'com.facebook.android:facebook-android-sdk:4.6.0'

编译'com.google.android.gms:play-services:7.5.0'

第 2 步:myActivity.xml

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

<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"/>

第 3 步:结果 第 4 步:使用最新的 gcm 更新 build.gradle在此处输入图像描述

compile 'com.facebook.android:facebook-android-sdk:4.6.0'
compile 'com.google.android.gms:play-services:8.4.0'

第 5 步:结果

在此处输入图像描述

于 2016-04-27T21:30:24.717 回答