Android为什么Facebook SDK注销按钮不显示?

问题描述:

我已经与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或是您的应用程序的一部分? –

尝试按照Facebook for Android Documentation

,并使用最新版本compile 'com.android.support:appcompat-v7:25.2.0'

Follow this tutorial

compile 'com.google.android.gms:play-services:10.2.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的代码,如果问题仍然没有解决。