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

一世执手 提交于 2019-12-07 04:53:00

问题


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?


回答1:


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" >



回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!