I'm using Facebook SDK 4.16.1 I'm wondering instead of using the default style of facebook login button how will I customize its style? I wanted to use an icon instead of a long button or edit its text if I will use the long button . How to do this? I tried using like below in my onCreate but it doesn't work like how it should be, It goes to the onActivityResult but ignores my FacebookCallback. Maybe I should still use <com.facebook.login.widget.LoginButton> but how will I change the style?
facebookButton = (ImageButton) findViewById(R.id.buttonFacebookLogin);
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
com.facebook.AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
FB_TOKEN=loginResult.getAccessToken().getToken();
id = profile.getId();
fname = profile.getFirstName();
lname = profile.getLastName();
name = profile.getName();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
response.getError();
Log.e("JSON-RESULT:", object.toString());
JSONObject jsonObject = null;
if (response.getError() != null) {
Toast.makeText(getApplicationContext(), response.getError().getErrorMessage(), Toast.LENGTH_SHORT).show();
}else {
try {
jsonObject = new JSONObject(object.toString());
email = jsonObject.getString("email");
gender = jsonObject.getString("gender");
locale = jsonObject.getString("locale");
verified = jsonObject.getString("verified");
Log.e(TAG, email + " This is the email");
saveToDB();
Toast.makeText(getApplicationContext(), "Logging in...", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link,birthday,first_name,last_name,email,gender,verified,locale");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException exception) {
Log.e("onError", exception.getMessage());
}
});
facebookButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LoginManager.getInstance().logInWithReadPermissions(SocialNetworkLoginActivity.this, Arrays.asList(Constants.FACEBOOK_PERMISSIONS));
}
});
My Constants.FACEBOOK_PERMISSIONS looks like this
public static final String[] FACEBOOK_PERMISSIONS = new String[] {
"public_profile",
"user_friends",
"email" };
My layout looks like this
<ImageButton
android:id="@+id/buttonFacebookLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_socialnetwork_facebook"
android:contentDescription="@string/content_desc_facebook"
android:src="@drawable/button_image_facebook" />