我使用ShareActionProvider在PopupMenu的,但显示两个PopupMenu的? [英] I Use ShareActionProvider in PopupMenu, but show two PopupMenu?

查看:209
本文介绍了我使用ShareActionProvider在PopupMenu的,但显示两个PopupMenu的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PopupMenu的使用ShareActionProvider,但是当我点击共享菜单项,它显示了两个PopupMenus在屏幕上,人们所涉及的其他。和一个显示应用程序图标和名称,另一个仅显示应用程序的名称。

它工作正常,但这个问题...
我该如何解决这个问题?

PS:请原谅我的不好EX pression

我的code是:

  PopupMenu的弹出=新PopupMenu的(这一点,按钮);
。popup.getMenuInflater()膨胀(R.menu.scrawl_popup_menu,popup.getMenu());
菜单项overflowItem = popup.getMenu()则findItem(R.id.popup_share)。
ShareActionProvider overflowProvider =
    (ShareActionProvider)overflowItem.getActionProvider();
overflowProvider.setShareHistoryFileName(
    ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
overflowProvider.setShareIntent(createShareIntent());
 

menu.xml文件是:

 < XML版本=1.0编码=UTF-8&GT?;
<菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目机器人:ID =@ + ID / popup_clear
        机器人:图标=@可绘制/ ic_menu_clear
        机器人:标题=@字符串/ popup_menu_clear/>
    <项目机器人:ID =@ + ID / popup_insert_bg
        机器人:图标=@可绘制/ ic_menu_insert_bg
        机器人:标题=@字符串/ popup_menu_insert_bg/>
    <项目机器人:ID =@ + ID / popup_share
        机器人:图标=@机器人:可绘制/ ic_menu_share
        机器人:标题=@字符串/ popup_menu_share
        机器人:actionProviderClass =android.widget.ShareActionProvider>
    < /项目>
< /菜单>
 

解决方案

我不得不使用startActivity(getShareIntent(/ status.jpg)); 当你想到这不起作用完全。然而,它可以用于同样的目的。希望它能帮助。

 私人意图getShareIntent(字符串文件路径){
        意图shareIntent =新的意图(Intent.ACTION_SEND);

        文件SD卡= Environment.getExternalStorageDirectory();

        文件sharedFile =新的文件(SD卡+ sharePath);
        开放的我们的uri = Uri.fromFile(sharedFile);

        shareIntent.setType(图像/ *);
        shareIntent.putExtra(Intent.EXTRA_STREAM,URI);
        返回shareIntent;
    }
 

不过,最后我搬到了使用操作栏与彭定康选择,而不是:   http://developer.android.com/design/patterns/selection.html

I use a ShareActionProvider in a PopupMenu, but when I click the share menu item, it shows two PopupMenus on the screen, one covered by the other. And one shows the application icon and name, the other one only shows the application name.

It works fine except this problem...
How can I fix it?

P.S.: please forgive me for my bad expression

My code is:

PopupMenu popup = new PopupMenu(this, button);
popup.getMenuInflater().inflate(R.menu.scrawl_popup_menu, popup.getMenu());
MenuItem overflowItem = popup.getMenu().findItem(R.id.popup_share);
ShareActionProvider overflowProvider =
    (ShareActionProvider) overflowItem.getActionProvider();
overflowProvider.setShareHistoryFileName(
    ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
overflowProvider.setShareIntent(createShareIntent());

menu.xml is:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/popup_clear"
        android:icon="@drawable/ic_menu_clear"
        android:title="@string/popup_menu_clear" />
    <item android:id="@+id/popup_insert_bg"
        android:icon="@drawable/ic_menu_insert_bg"
        android:title="@string/popup_menu_insert_bg"/>
    <item android:id="@+id/popup_share"
        android:icon="@android:drawable/ic_menu_share"
        android:title="@string/popup_menu_share"
        android:actionProviderClass="android.widget.ShareActionProvider">
    </item>
</menu>

解决方案

I had to use startActivity(getShareIntent("/status.jpg")); This doesn't work exactly as you expect. However, it can be used for the same purpose. Hope it help.

private Intent getShareIntent(String filePath) {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);

        File sdCard = Environment.getExternalStorageDirectory();

        File sharedFile = new File(sdCard + sharePath);
        Uri uri = Uri.fromFile(sharedFile);

        shareIntent.setType("image/*");
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        return shareIntent;
    }

However, finally I moved to use action bar with Selection patten instead: http://developer.android.com/design/patterns/selection.html

这篇关于我使用ShareActionProvider在PopupMenu的,但显示两个PopupMenu的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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