Android - 如何更改Facebook登录按钮上的文本

13

我想要改变安卓Facebook登录按钮上的文本。

我已经看过许多Stack Overflow的答案,但是没有一个能够解决我的问题。有没有一种方法可以更改它呢?

我尝试了这些链接中的答案:[1][1], [2][2], [3][3]。

如果我使用com.facebook.login.widget.LoginButton按钮,我无法更改按钮上的文本。(虽然我可以登录)

<com.facebook.login.widget.LoginButton
    android:id="@+id/fragment_login_fb_login_button"
    android:layout_width="@dimen/fragment_login_fb_button_width"
    android:layout_height="@dimen/fragment_login_fb_button_height"
    android:layout_gravity="center"
    android:layout_marginTop="@dimen/fragment_login_fb_button_top_margin"
    android:background="@drawable/fragment_login_fb_login_button_background"
    android:drawableLeft="@drawable/facebook_icon"
    android:gravity="center"
    android:text="@string/label_fragment_login_sign_in_with_facebook"
    android:textColor="@android:color/white"
    android:textStyle="bold"/>
如果我使用Button,我可以更改文本,但我无法登录。
<Button
    android:id="@+id/fragment_login_fb_login_button"
    android:layout_width="@dimen/fragment_login_fb_button_width"
    android:layout_height="@dimen/fragment_login_fb_button_height"
    android:layout_gravity="center"
    android:layout_marginTop="@dimen/fragment_login_fb_button_top_margin"
    android:background="@drawable/fragment_login_fb_login_button_background"
    android:drawableLeft="@drawable/facebook_icon"
    android:gravity="center"
    android:text="@string/label_fragment_login_sign_in_with_facebook"
    android:textColor="@android:color/white"
    android:textStyle="bold"/>

我正在使用 Android Facebook SDK 版本 4.5.0。 [1]: 如何自定义 Android Facebook 登录按钮 [2]: 在 Facebook Android SDK3 中更改 Facebook 登录按钮图像是否可行? [3]: 如何在 Facebook Android SDK 4.0 中设置登录/注销按钮文本?


在你的strings.xml文件中,@string/label_fragment_login_sign_in_with_facebook是指什么? - random
使用Facebook登录 - VK.N
4个回答

55
你可以尝试使用Facebook名称空间,并为其设置com_facebook_login_text属性。
<com.facebook.login.widget.LoginButton
        xmlns:facebook="http://schemas.android.com/apk/res-auto"
        facebook:com_facebook_login_text="YourText"/>

2
它运行良好。对于登录注销自定义文本,请尝试以下内容 - xmlns:facebook ="http://schemas.android.com/apk/res-auto" facebook:com_facebook_login_text ="YourText" facebook:com_facebook_logout_text ="Your Logout text" - Mahmudur Rahman
3
它在设备上运行良好,但在Android Studio的预览中不起作用。 - Khizar Hayat

0
请查阅许可协议,您会发现您不被允许更改它。同时您也不能更改"f"。根据许可协议,您唯一被允许的是使用不同的标准颜色。请参考fb中的7.3和assets中所允许的品牌。

谢谢你的更新,但它并没有明确说明“您无法更改登录按钮上的文本”。你的答案帮助我使用了Facebook SDK登录按钮。 - VK.N
从我的个人经验来看,一切都可能很顺利,但他们可能只需要一天就能发现问题,然后你就得修复它...而且他们并不关心你有多少活跃用户。他们只会关闭你的服务。附言:这是我的个人经验,如果有帮助,也许你可以将其设置为答案。谢谢。 - danysz

0

在预览中无法运行设备

       <com.facebook.login.widget.LoginButton
        android:layout_height="wrap_content"
        android:id="@+id/signup_signupFacebookButton"
        android:layout_width="fill_parent"
        xmlns:facebook="http://schemas.android.com/apk/res-auto"
        facebook:com_facebook_login_text="Sign up with Facebook"/>

0

这只是一个技巧,而不是正式的方法。

  • 创建一个相对布局。
  • 定义您的Facebook按钮。
  • 还要定义您的自定义设计按钮。
  • 将它们重叠在一起。
<RelativeLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp">
    <com.facebook.login.widget.LoginButton
    xmlns:facebook="http://schemas.android.com/apk/res-auto"
    android:id="@+id/login_button"
    android:layout_width="300dp"
    android:layout_height="100dp"
    android:paddingTop="15dp"
    android:paddingBottom="15dp" />
    <LinearLayout
    android:id="@+id/llfbSignup"
    android:layout_width="300dp"
    android:layout_height="50dp"
    android:background="@drawable/facebook"
    android:layout_gravity="center_horizontal"
    android:orientation="horizontal">
    <ImageView
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:src="@drawable/facbk"
    android:layout_gravity="center_vertical"
    android:layout_marginLeft="10dp" />
    <View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:background="@color/fullGray"
    android:layout_marginLeft="10dp"/>
    <com.yadav.bookedup.fonts.GoutamBold
    android:layout_width="240dp"
    android:layout_height="50dp"
    android:text="Sign Up via Facebook"
    android:gravity="center"
    android:textColor="@color/white"
    android:textSize="18dp"
    android:layout_gravity="center_vertical"
    android:layout_marginLeft="10dp"/>
    </LinearLayout>
</RelativeLayout>

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