无法将com.facebook.share.widget.Sharebutton添加到布局XML [英] Unable to add com.facebook.share.widget.Sharebutton to Layout XML

查看:99
本文介绍了无法将com.facebook.share.widget.Sharebutton添加到布局XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android中使用Facebook SDK从我的应用程序中共享内容的方向

我正在 Facebook文档上从此处使用以下代码:

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);

问题是-在XML文件中,我需要将 com.facebook.share.widget.Sharebutton 添加到XML,但无法被识别.

com.facebook.share.widget.Sharebutton 是为此Sharebutton添加的正确XML元素吗?

解决方案

在主布局中添加此行

xmlns:facebook="http://schemas.android.com/apk/res-auto"

像这样

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

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

这篇关于无法将com.facebook.share.widget.Sharebutton添加到布局XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆