ShareActionProvider一个图标 - 寻找简单actionitem [英] ShareActionProvider with one icon - looking as simple actionitem

查看:107
本文介绍了ShareActionProvider一个图标 - 寻找简单actionitem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想dislay ShareActionProvider 动作条,而是使用自定义外观和放大器;感觉。只有一个无国界,无右边最常用的应用程序图标简单的共享图标。但是,提供弹出菜单中最常用的应用程序。有一个简单的办法做到这一点没有实现自己的 ShareActionProvider

I want to dislay ShareActionProvider on ActionBar, but with custom look&feel. Only one simple share icon without borders and without most used app icon on the right. But providing popup menu with most used applications. Is there a simple way to do it without implementing own ShareActionProvider?

推荐答案

行,所以不管ActionBarSherlock第一个测试,看看你正确地创建你的意图,ABS使用相同的code作为通用选择器确实如此,如果看到应用程序的您正在寻找的表演,当您执行此code。

OK so regardless of ActionBarSherlock first test to see if your creating your intent correctly, ABS uses the same code as the generic chooser does so see if the app's you are looking for show up when you execute this code.

Intent I= new Intent(Intent.ACTION_SEND);
I.setType("text/plain");
I.putExtra(android.content.Intent.EXTRA_TEXT, "My Test Text");

startActivity(Intent.createChooser(I,"Share using ..."));

所有这些应用程序的那处理纯文本将显示出来,如果​​Facebook,或任何你期望是不是有那么这些应用程序的不支持ACTION_SEND意图已注册的类型(普通/文)。 (Facebook的做法,但更多的是在一分钟内)

All of that app's that handle plain text will show up, if facebook, or whatever you are expecting is not there then those app's don't support the ACTION_SEND intent for the type you have registered (plain/text). (Facebook does, but more about that in a minute)

ABS有一个样品使用份额的行动提供者,但尝试的发送照片,而不是短信(状态更新),你应该使用的设置是这样的

ABS has a sample for using the share action provider but it try's to send a photo, not a text message (status update) the setup you should be using is something like this

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate your menu.
    getSupportMenuInflater().inflate(R.menu.share_action_provider, menu);

// Set file with share history to the provider and set the share intent.
MenuItem item = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
ShareActionProvider provider = (ShareActionProvider) item.getActionProvider();
              provider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
// Note that you can set/change the intent any time,
// say when the user has selected an image.
provider.setShareIntent(createShareIntent());

return true
}

这里是将用于满足应用程序的,并列出他们从样本的意图

And here is the intent that will be used to match app's and list them out from the sample

private Intent createShareIntent() {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("image/plain");
        Uri uri = Uri.fromFile(getFileStreamPath("shared.png"));
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        shareIntent.putExtra(Intent.EXTRA_TITLE, "This is an android icon");
        return shareIntent;
    }

但你希望它是

but you want it to be

private Intent createShareIntent() {
        Intent I= new Intent(Intent.ACTION_SEND);
        I.setType("text/plain");
        I.putExtra(android.content.Intent.EXTRA_SUBJECT, "TEST - Disregard");
        I.putExtra(android.content.Intent.EXTRA_TEXT, Uri.parse("http://noplace.com"));
    }

这应该给你相同的列表中ABS它在小试桩我发现与上述选择器一样。

This should give you the same list in ABS at it did in the small test stub I showed with the chooser above.

这篇关于ShareActionProvider一个图标 - 寻找简单actionitem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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