I am trying to use Facebook SDK in Android to Share Content Direction from my app.
I'm using the following code from here on Facebook Docs:
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("http://www.focusoutdistractions.com/"))
.build();
ShareButton shareButton = (ShareButton) rootView.findViewById(R.id.ibtn_twshare);
shareButton.setShareContent(content);
Question is - In the XML file, I need to add com.facebook.share.widget.Sharebutton to the XML but it is not getting recognized.
Is com.facebook.share.widget.Sharebutton the correct XML element to add for this Sharebutton?
Add this line in the main layout
xmlns:facebook="http://schemas.android.com/apk/res-auto"
like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
Yes, com.facebook.share.widget.ShareButton
is correct XML element. It will not be rendered by preview of XML layout, but don't worry about it. The app will compile without problems, and running app will show it properly.
<com.facebook.share.widget.ShareButton
android:id="@+id/shareButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp" />

来源:https://stackoverflow.com/questions/29340092/unable-to-add-com-facebook-share-widget-sharebutton-to-layout-xml