Custom Facebook Login Button Android

To Creating a facebook login button, I followed facebook documentation and after that my login is working perfectly but I want to customize my button for that I tried lot things but nothing working.

1) First I tried from xml like this:

<com.facebook.login.widget.LoginButton
        android:id="@+id/authButton"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_marginRight="30dp"
        android:layout_marginLeft="30dp"
        android:padding="10dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="30dp"
        android:textColor="@color/white"
        android:background="@drawable/fbbutton_state"
        android:textSize="15sp"
        android:text="Facebook"
        />

2) Created custom class and extended LoginButton.

public class CustomLoginButton extends LoginButton {

public CustomLoginButton(Context context, AttributeSet attrs) {
    super(context, attrs)
     this.setBackgroundColor(R.color.com_facebook_likeboxcountview_border_color);
    this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.my_own_icon, 0, 0, 0);
    this.setText("Facebook");
}

}

in this icon color changed but still text .

3)And finally I tried in facebook sdk, I changed strings and style, it must work but no result

<string name="com_facebook_loginview_log_in_button">Log in via Facebook</string> 


<style name="com_facebook_loginview_default_style" parent="@android:style/Widget.Button">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">45dp</item>
        <item name="android:background">@drawable/com_facebook_button_blue</item>
        <item name="android:textColor">@color/com_facebook_loginview_text_color</item>
        <item name="android:textSize">@dimen/com_facebook_loginview_text_size</item>
        <item name="android:textStyle">bold</item>
        <item name="android:paddingLeft">@dimen/com_facebook_loginview_padding_left</item>
        <item name="android:gravity">center</item>
    </style>

One difference I found in my login button and common SO login buttons is they are like: <com.facebook.widget.LoginButton and mine like this: <com.facebook.login.widget.LoginButton but I think facebook upgraded this thing.


Source: facebook

Leave a Reply