完整内容,请查看:http://www.zhdoc.net/android/reference/android/widget/ShareActionProvider.html
ShareActionProvider
public class ShareActionProvider
extends ActionProvider
java.lang.Object | ||
↳ | android.view.ActionProvider | |
↳ | android.widget.ShareActionProvider |
This is a provider for a share action. It is responsible for creating views that enable data sharing and also to show a sub menu with sharing activities if the hosting item is placed on the overflow menu.
一个分享操作的provider。它负责创建支持数据分享的视图,并且如果将托管项放置在溢出菜单上,还可以显示带有分享activity的子菜单。
Here is how to use the action provider with custom backing file in a MenuItem
:
下面是如何在MenuItem
中使用自定义支持文件的ActionProvider:
// In Activity#onCreateOptionsMenu public boolean onCreateOptionsMenu(Menu menu) { // Get the menu item.MenuItem menuItem = menu.findItem(R.id.my_menu_item); // Get the provider and hold onto it to set/change the share intent. mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider(); // Set history different from the default before getting the action // view since a call toMenuItem.getActionView()
calls //onCreateActionView()
which uses the backing file name.Omit this // line if using the default share history file is desired. mShareActionProvider.setShareHistoryFileName("custom_share_history.xml"); .。。} // Somewhere in the application. public void doShare(Intent shareIntent) { // When you want to share set the share intent. mShareActionProvider.setShareIntent(shareIntent); }
Note: While the sample snippet demonstrates how to use this provider in the context of a menu item, the use of the provider is not limited to menu items.
注意:尽管示例代码片段演示了如何在菜单项的上下文中使用该provider,但provider的使用并不仅限于菜单项。
See also:
另请参考:
摘要
嵌套类 | |
---|---|
interface | ShareActionProvider.OnShareTargetSelectedListener Listener for the event of selecting a share target. |
常量 | |
---|---|
String | DEFAULT_SHARE_HISTORY_FILE_NAME The default name for storing share history. |
Public构造方法 | |
---|---|
ShareActionProvider(Context context) Creates a new instance. |