Failed to add com.facebook.share.widget.Sharebutton to Layout XML

I am trying to use the Facebook SDK in Android for Share Content Referral from my application.

I use the following code from here 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 . In the XML file, I need to add com.facebook.share.widget.Sharebutton to the XML, but it is not recognized.

Is com.facebook.share.widget.Sharebutton the correct XML element to add for this Sharebutton?

+4
source share
2 answers

Add this line to 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" >
+3
source

, com.facebook.share.widget.ShareButton - XML-. XML-, . , .

<com.facebook.share.widget.ShareButton
        android:id="@+id/shareButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" />

enter image description here

+4

All Articles