Can I change the image of the Facebook login button in the Android Android SDK3?

Facebook Android sdk has com.facebook.widget.LoginButton

I want to place my own image for the Login button. Is it possible?

So far I have tried to add android:src="@drawable/facebook" to the layout file as an attribute of a button element with no luck

+33
android facebook-android-sdk
May 11 '13 at 11:46
source share
3 answers

I ended up redefining the text as an empty string, and then defined the setBackgroundResource buttons on my image (did not need a dynamic login / logout function)

 <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 in the code, I defined a background resource:

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

Kind of a workaround, but I preferred it to change the SDK code for Facebook (although it is very straight forward), and worry about updating every time I update their version.

+78
May 13 '13 at 21:42
source share

yes, if you want to change the text and image, then write the code below.

 authButton = (LoginButton) view.findViewById(R.id.authButton); authButton.setBackgroundResource(R.drawable.icon); authButton.setText("Login"); authButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);` 
+9
Oct. 16 '14 at 12:45
source share

Another way

 loginButton = (LoginButton) findViewById(R.id.fb_login_button); loginButton.setVisibility(View.GONE); ImageView ivFbCustomButton = (ImageView) findViewById(R.id.iv_fb_custom_button); ivFbCustomButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { com.facebook.login.widget.LoginButton btn = new com.facebook.login.widget.LoginButton(FacebookActivity.this); btn.performClick(); } }); 

Note:

You need to write code for two buttons in an XML file. One for the facebook button by default (we hide it in the initial step). Second for custom button

+1
Dec 17 '16 at 11:15
source share



All Articles