分享图标,在动作条不显示 [英] Share icon not showing in ActionBar

查看:153
本文介绍了分享图标,在动作条不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ShareActionProvider如 http://developer.android.com/培训/共享/ shareaction.html 但是我的动作条不显示共享图标。相反,溢出按钮显示它的菜单项共享(其余效果很好)。我用这code:

I am trying to use ShareActionProvider as in http://developer.android.com/training/sharing/shareaction.html but my ActionBar does not show the share icon. Instead, the overflow button is shown which a menu item "share" (the rest works well). I am using this code:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_item_share"
    android:title="share"
    compat:showAsAction="ifRoom|collapseActionView"
    android:actionProviderClass="android.widget.ShareActionProvider"/>
</menu>

在我的活动,我有:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate menu resource file.
    getMenuInflater().inflate(R.menu.menu_detail, menu);

    // Locate MenuItem with ShareActionProvider
    MenuItem item = menu.findItem(R.id.menu_item_share);

    // Fetch and store ShareActionProvider
    mShareActionProvider = (ShareActionProvider) item.getActionProvider();

    // Return true to display menu
    return super.onCreateOptionsMenu(menu);
}

// Call to update the share intent
private void setShareIntent(Intent shareIntent) {
    if (mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(shareIntent);
    }
}

和我的主题是:

<style name="Theme.Base" parent="android:Theme.Light" />

<style name="AppTheme" parent="Theme.Base">
    <item name="android:actionModeCloseDrawable">@drawable/ic_action_back</item>
</style>

为什么不共享图标显示不出来?

Why is does the share icon not show up?

推荐答案

你的一些code的( COMPAT:showAsAction )写入使用应用程序兼容性-V7 的下行移植行动吧。

Some of your code (compat:showAsAction) is written to use the appcompat-v7 backport of the action bar.

你的一些code的( getActionProvider() Theme.Light )写入使用本土行动起来吧。

Some of your code (getActionProvider(), Theme.Light) is written to use the native action bar.

选择一个,并坚持下去。

我的猜测是,更多的你当前的code被设置为本地操作栏,在这种情况下,改变 compat的: Android的:菜单中的XML资源可能会得到你的 ShareActionProvider 工作

My guess is that more of your current code is set up for the native action bar, in which case changing compat: to android: in your menu XML resource will probably get your ShareActionProvider working.

这篇关于分享图标,在动作条不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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