在 Facebook Android SDK 4.0 中设置 Login/Logout 按钮文本?

Set Login/Logout Text for Button in Facebook Android SDK 4.0?

我的xml看起来像这样

<com.facebook.login.widget.LoginButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fb_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="CONNECT WITH FACEBOOK"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold"
android:background="@drawable/button_fb_login"/>

背景绘图 xml 是

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
    <shape>
        <solid android:color="#4e69a2" />
        <stroke android:width="3dip" android:color="#4e69a2" />
        <padding android:bottom="0dip" android:left="0dip" android:right="0dip" android:top="0dip" />
    </shape>
</item>

<item>
    <shape>
        <solid android:color="#3b5998" />
        <stroke android:width="3dip" android:color="#3b5998" />
        <padding android:bottom="0dip" android:left="0dip" android:right="0dip" android:top="0dip" />
    </shape>
</item>

现在在 android 工作室预览屏幕中,它按预期显示。

但是当我在我的 phone 或模拟器上 运行 它时,它默认显示“使用 FACEBOOK 登录”,就像这样

如何在 运行 应用程序中获取我的自定义文本?

使用facebook:login_textfacebook:logout_text

 <com.facebook.widget.LoginButton
            android:id="@+id/login_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            facebook:confirm_logout="false"
            facebook:fetch_user_info="true"
            android:text="testing 123"
            facebook:login_text="LOGIN"
            facebook:logout_text="LOGOUT"
            />

如果上述方法不起作用,请尝试在您的值文件夹中添加以下内容

<resources>
<string name="com_facebook_loginview_log_in_button">LOGIN</string>
<string name="com_facebook_loginview_log_out_button">LOGOUT</string>
</resources>

更新:可能原因

https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/login/widget/LoginButton.java#L599

更新 2:可能的解决方案

覆盖 strings.xml

中的那些字符串
<string name="com_facebook_loginview_log_out_button">Log out</string>
<string name="com_facebook_loginview_log_in_button">Log in</string>
<string name="com_facebook_loginview_log_in_button_long">Log in with Facebook</string>

可以找到其他字符串here

只需相应地更改属性即可。参考:this

例如:

<com.facebook.login.widget.LoginButton
        xmlns:facebook="http://schemas.android.com/apk/res-auto"
        facebook:com_facebook_login_text="LOGIN"/>