2015-10-18 102 views
0

我想在我的應用程序中使用分享按鈕,但它看起來好像它被禁用:分享按鈕看起來禁用

disabled share button

我已經初始化SDK:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    FacebookSdk.sdkInitialize(getApplicationContext()); 
} 

我也有像文檔建議正確配置清單: https://developers.facebook.com/docs/android/getting-started

按鈕該視圖是這樣的:

<com.facebook.share.widget.ShareButton 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/share" 
       android:id="@+id/share_on_fb_button" 
       bind:onClick="shareOnFBButtonClick"/> 

可能是什麼問題?爲什麼按鈕被禁用?我應該在我的應用中實現登錄功能嗎?或者我只需要在設備上安裝Facebook應用程序?

回答

3

見com.facebook.share.widget.ShareButtonBase:

/** 
* Sets the share content on the button. 
* @param shareContent The share content. 
*/ 
public void setShareContent(final ShareContent shareContent) { 
    this.shareContent = shareContent; 
    if (!enabledExplicitlySet) { 
     internalSetEnabled(canShare()); 
    } 
} 

調用setShareContent使shareButton,試試吧:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    FacebookSdk.sdkInitialize(getApplicationContext()); 
    setContentView(R.layout.activity_main); 

    ShareButton fbShareButton = (ShareButton) findViewById(R.id.share_on_fb_button); 
    ShareLinkContent content = new ShareLinkContent.Builder() 
      .setContentUrl(Uri.parse("https://developers.facebook.com")) 
      .build(); 
    fbShareButton.setShareContent(content); 
} 

注: https://developers.facebook.com/docs/sharing/android

「當你實現共享,你的應用不應該預先填充任何要共享的內容,這與Facebook平臺政策不一致,請參閱Facebook平臺政策,2.3。「

+0

我沒有設置要共享的內容。這解決了這個問題;) – amp

+0

這可行,但如果我想分享照片,該按鈕仍然是禁用的 –