Set Login/Logout Text for Button in Facebook Andro

2019-03-22 22:38发布

My xml looks like this

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

and background drawble xml is

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

Now in android studio preview screen it shows as expected.

enter image description here

But when I run it on my phone or emulator, it shows "LOG IN WITH FACEBOOK" by default, like this

enter image description here

How do I get my custom text on running the application?

2条回答
冷血范
2楼-- · 2019-03-22 23:22

use facebook:login_text and facebook: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"
            />

If the above doesnt work, try to add following in your values folder

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

Update: Possible cause

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

Update 2: Possible Solution

Override those strings in your 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>

Other strings can be found here

查看更多
女痞
3楼-- · 2019-03-22 23:29

Just need change the attribute accordingly. Refer to : this

eg:

<com.facebook.login.widget.LoginButton
        xmlns:facebook="http://schemas.android.com/apk/res-auto"
        facebook:com_facebook_login_text="LOGIN"/>
查看更多
登录 后发表回答