4

我已經與Facebook登錄的應用程序,沒有在登錄過程沒有問題。但是當我想註銷時,我看不到按鈕。Android爲什麼Facebook SDK註銷按鈕不顯示?

破碎應用截圖

BROKEN APP

工作程序截圖

WORKING APP

破碎的Gradle應用程序文件;

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 24 
    buildToolsVersion "24.0.1" 
    defaultConfig { 
     applicationId "com.ex.ex" 
     minSdkVersion 15 
     targetSdkVersion 24 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 

    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 

    // Glide image library 
    compile 'com.android.support:appcompat-v7:24.2.1' 
    compile 'com.android.support:design:24.2.1' 
    compile 'com.android.support:support-v4:24.2.1' 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
    compile 'com.google.android.gms:play-services-auth:9.2.1' 
    compile 'com.facebook.android:facebook-android-sdk:4.1.0' 

    testCompile 'junit:junit:4.12' 
} 

apply plugin: 'com.google.gms.google-services' 

什麼是問題的根源?我怎樣才能解決這個問題?

謝謝。

+1

如果你發佈活動代碼和XML的東西也許有用。可能是一個檢查,如果你登錄你不顯示按鈕。 – Flummox

+0

在您點擊Facebook按鈕後打開的'AlertDialog'附帶Facebook SDK或是您的應用程序的一部分? –

回答

0

我假設你已經使用Facebook的Android SDK中的LoginButton部件。

當您單擊的LoginButton控件下面的代碼註銷執行:

protected void performLogout(Context context) { 
     final LoginManager loginManager = getLoginManager(); 
     if (confirmLogout) { 
      // Create a confirmation dialog 
      String logout = getResources().getString(
        R.string.com_facebook_loginview_log_out_action); 
      String cancel = getResources().getString(
        R.string.com_facebook_loginview_cancel_action); 
      String message; 
      Profile profile = Profile.getCurrentProfile(); 
      if (profile != null && profile.getName() != null) { 
       message = String.format(
         getResources().getString(
           R.string.com_facebook_loginview_logged_in_as), 
         profile.getName()); 
      } else { 
       message = getResources().getString(
         R.string.com_facebook_loginview_logged_in_using_facebook); 
      } 
      AlertDialog.Builder builder = new AlertDialog.Builder(context); 
      builder.setMessage(message) 
        .setCancelable(true) 
        .setPositiveButton(logout, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          loginManager.logOut(); 
         } 
        }) 
        .setNegativeButton(cancel, null); 
      builder.create().show(); 
     } else { 
      loginManager.logOut(); 
     } 

}

confirmLogout標誌被默認設置爲true,除非指定窗口小部件的XML文件錯誤:

confirmLogout = a.getBoolean(R.styleable.com_facebook_login_view_com_facebook_confirm_logout, true); 

所以請檢查你的xml文件confirm_logout是否設置爲false。 但是,在這種情況下,用戶將以靜默方式退出而不顯示警報對話框。

請發表您的java的代碼和XML的代碼,如果問題仍然沒有解決。