Java 自定义Facebook共享按钮,Android应用程序
因此,我想在我的Android应用程序中实现一个定制的Facebook共享按钮,但到目前为止,我只使用了本机按钮,我将其导入到.xml文件中,并在Java活动中用于该特定页面 我的代码在.xml中看起来像这样Java 自定义Facebook共享按钮,Android应用程序,java,android,xml,facebook,Java,Android,Xml,Facebook,因此,我想在我的Android应用程序中实现一个定制的Facebook共享按钮,但到目前为止,我只使用了本机按钮,我将其导入到.xml文件中,并在Java活动中用于该特定页面 我的代码在.xml中看起来像这样 <com.facebook.share.widget.ShareButton android:id="@+id/share_btn" android:layout_width="wrap_content" and
<com.facebook.share.widget.ShareButton
android:id="@+id/share_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="Share"
android:layout_centerHorizontal="true"/>
内部onCreate
private ShareButton shareButton;
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://developers.facebook.com"))
.setContentTitle("MyTitle")
.build();
shareButton = (ShareButton)findViewById(R.id.share_btn);
shareButton.setShareContent(content);
如何使用导入到XML中的自定义按钮?如果不是ShareButton的实例,那么使用.setShareContent显然不起作用。提前谢谢 我找到了解决办法。很明显,facebook共享将在其自己的按钮点击事件中发挥作用。因此,必须显式调用View.performclick方法 我是这样做的: 在我的布局中
<com.facebook.share.widget.ShareButton
android:id="@+id/share_btn_fb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:contentDescription="@string/share" />
<LinearLayout
android:id="@+id/share_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="@drawable/google_share" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/share_google"
android:textColor="@color/green_color"
android:layout_marginLeft="5dp"
android:textSize="18sp" />
</LinearLayout>
内翻舔
基本上是shareButton.performClick;我找到了一个解决办法。很明显,facebook共享将在其自己的按钮点击事件中发挥作用。因此,必须显式调用View.performclick方法 我是这样做的: 在我的布局中
<com.facebook.share.widget.ShareButton
android:id="@+id/share_btn_fb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:contentDescription="@string/share" />
<LinearLayout
android:id="@+id/share_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="@drawable/google_share" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/share_google"
android:textColor="@color/green_color"
android:layout_marginLeft="5dp"
android:textSize="18sp" />
</LinearLayout>
内翻舔
基本上是shareButton.performClick;正在玩把戏。找到解决方案了吗?我也陷入了同样的境地。找到解决办法了吗?我也陷入了同样的境地。
case R.id.share_btn :
shareButton.performClick();
break;
case R.id.share_btn_fb :
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentTitle("Content title")
.setContentDescription("App descr")
.setContentUrl(Uri.parse("some url"))
.build();
shareButton.setShareContent(content);
break;