Facebook login button: custom style applied

I had a strange problem using the new Android android sdk 4. With an older version of sdk I used:

<com.facebook.login.widget.LoginButton xmlns:fb="http://schemas.android.com/apk/res-auto" android:id="@+id/fb_button" style="@style/FacebookLoginButton" android:layout_width="485dp" android:layout_height="64dp" android:layout_centerHorizontal="true" android:layout_marginBottom="-17dp" fb:login_text="@string/login_with_facebook" fb:logout_text="Logout" /> 

The FacebookLoginButton section for the .xml style looks like

 <style name="FacebookLoginButton"> <item name="android:background">@drawable/button_facebook</item> <item name="android:textColor">@color/white</item> <item name="android:textSize">21sp</item> <item name="android:gravity">center</item> </style> 

drawable / button_facebook contains png custom button shapes. Now that the old version of sdk everithing works fine, but something went wrong with the new sdk. I get this:

enter image description here

as you can see, theres two facebook icon: a round button with a facebook button, the second (large) button belongs to the button_facebook button, which can be unloaded). Is there a way to hide the icon mug?

+8
android facebook facebook-android-sdk
source share
4 answers

Even I encountered the same problem while I was working with fb login .... I fixed the problem by adding the following code ....

  fbLoginButton.setBackgroundResource(R.drawable.facebook); fbLoginButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); fbLoginButton.setCompoundDrawablePadding(0); fbLoginButton.setPadding(0, 0, 0, 0); fbLoginButton.setText(""); 

and here is my xml layout:

 <com.facebook.widget.LoginButton xmlns:fb="http://schemas.android.com/apk/res-auto" android:id="@+id/fbLoginButton" android:layout_width="fill_parent" android:layout_height="wrap_content" fb:login_text="" fb:logout_text="" android:scaleType="centerInside" /> 

Hope this helps you.

EDIT 1:
Facebook may change the location of the LoginButton class that is present in its SDK, so you may need to change the XML tag accordingly. In my case, it was inside com.facebook.widget.LoginButton , double check it.

+14
source share

In the latest v4 API for Facebook, this is the correct answer:

 <com.facebook.login.widget.LoginButton xmlns:facebook="http://schemas.android.com/apk/res-auto" facebook:com_facebook_login_text="LOGIN" facebook:com_facebook_logout_text="LOGOUT"/> 
+19
source share

You can simply use android:drawableLeft="@null" to get rid of the small Facebook icon

+4
source share
 <FrameLayout android:id="@+id/facebook_lay" android:layout_width="0dp" android:layout_height="40dp" android:layout_weight="1" android:background="@drawable/facebook_button_bg"> <com.lovetohave.love.ui.LoveTextView android:id="@+id/facebook_txt" android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/selectableItemBackgroundBorderless" android:clickable="true" android:gravity="center" android:text="@string/facebook" android:textColor="@color/white" android:textSize="@dimen/material_small" app:customFont="fonts/Roboto-Medium.ttf" /> <com.rey.material.widget.ProgressView android:id="@+id/fb_progress_view_cir" android:layout_width="20dp" android:layout_height="20dp" android:layout_gravity="center" android:visibility="gone" app:cpd_strokeColor="#fff" app:cpd_strokeSize="1dp" app:pv_autostart="true" app:pv_circular="true" app:pv_progressMode="indeterminate" app:pv_progressStyle="@style/CircularProgress1" /> </FrameLayout> 

You can create a design as a text box or button. and add the following code inside the button click event.

 LoginManager.getInstance().logOut(); LoginManager.getInstance().logInWithReadPermissions(SignIn.this, permissionNeeds); 

Then enter the following code in the onCreate method to get the profile information

 LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { mAccessToken = loginResult.getAccessToken() .getToken(); PrefUtil.saveData("accesstoken", mAccessToken, SignIn.this); GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(org.json.JSONObject object, GraphResponse response) { } catch (org.json.JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }); Bundle parameters = new Bundle(); parameters .putString( "fields", "id,name,email,gender,birthday,first_name,last_name,location,picture"); request.setParameters(parameters); request.executeAsync(); } @Override public void onCancel() { Log.i(TAG, "LoginManager FacebookCallback onCancel"); mFbProgressBar.setVisibility(View.GONE); mFacebookTxt.setVisibility(View.VISIBLE); if (pendingAction != PendingAction.NONE) { showAlert(); pendingAction = PendingAction.NONE; } } @Override public void onError(FacebookException exception) { mFbProgressBar.setVisibility(View.GONE); mFacebookTxt.setVisibility(View.VISIBLE); Log.i(TAG, "LoginManager FacebookCallback onError"); if (pendingAction != PendingAction.NONE && exception instanceof FacebookAuthorizationException) { showAlert(); pendingAction = PendingAction.NONE; } } private void showAlert() { new AlertDialog.Builder(SignIn.this) .setTitle(R.string.cancelled) .setMessage(R.string.permission_not_granted) .setPositiveButton(R.string.ok, null).show(); } }); 
0
source share

All Articles