Custom Facebook login button image in Facebook Android SDK 3.5

Jon G picture Jon G · Sep 18, 2013 · Viewed 13.2k times · Source

In a similar vein to this queston related to Facebook Android SDK 3.0 ...

Is it possible to use my own image for the Facebook login button in SDK 3.5, without customising the SDK itself?

Using the answer given in the linked question:

<com.facebook.widget.LoginButton
    xmlns:fb="http://schemas.android.com/apk/res-auto"
    android:id="@+id/login_button"
    android:layout_width="249dp"
    android:layout_height="45dp"
    android:layout_above="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:layout_marginBottom="30dp"
    android:layout_marginTop="30dp"
    android:contentDescription="@string/login_desc"
    android:scaleType="centerInside"
    fb:login_text=""
    fb:logout_text="" />

and:

final LoginButton button = (LoginButton) findViewById(R.id.login_button);
button.setBackgroundResource(R.drawable.facebook);

I am seeing two images with the new SDK. My image (R.drawable.facebook) is a large grey background with a white "f". However, I am also seeing the small white background and transparent "f" coming from the original facebook button icon overlayed on top of the background. See the facebook docs related to the SDK 3.5 log in button. I want to remove the original facebook icon completely.

Answer

Ming Li picture Ming Li · Sep 18, 2013

In addition to setting the background resource, also call:

button.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0);