0
我正在使用Facebook SDK 4.16.1
我想知道,而不是使用Facebook的默認樣式login button
我將如何定製其風格?如果我使用長按鈕,我想使用圖標而不是長按鈕或編輯其文本。這個怎麼做?我嘗試在我的onCreate
中使用類似以下內容,但它不適用於它應該如何使用,它轉到onActivityResult
,但忽略了我的FacebookCallback
。也許我仍然應該使用<com.facebook.login.widget.LoginButton>
但我將如何改變風格?如何自定義Facebook的樣式LoginButton,但仍然正確登錄
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));
}
});
我Constants.FACEBOOK_PERMISSIONS
看起來像這樣
public static final String[] FACEBOOK_PERMISSIONS = new String[] {
"public_profile",
"user_friends",
"email" };
我的佈局看起來像這樣
<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" />
只需使用'Button'而不是'com.facebook.login.widget.LoginButton' –
使用您自己的按鈕 – Piyush
我使用了我自己的'Button' /'ImageButton',就像上面那樣,但它不起作用。我錯過了什麼嗎? – natsumiyu