joao da silva
joao da silva

Reputation: 43

share menu using android.support.v7 doesn't show the apps icons

I'm trying to share a simple text using ShareActionProvider with android.support.v7 to put a Share-button in the ActionBar. My App must work with minimal API Level 8. The Problem: When I emulate the code with API 19 (targel level) it works fine, but when I emulate with an API-8 device, the pop-up menu with the list of apps to share shows only the name of the apps, without its icons. I tried with a real android device with API-9 and got the same problem: no icons too. Here are my codes:

in menu.xls:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="package.ActivityName" >


    <item
        android:id="@+id/menuitemShare"
        android:orderInCategory="1"
        android:title="@string/menu1"
        android:icon="@drawable/ic_action_share"
        app:showAsAction="ifRoom"
        app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
        />

</menu>

in java activity:

public class ActivityName extends ActionBarActivity  {


    private ShareActionProvider mShareActionProvider;
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.bem_vindo2, menu);
        MenuItem shareItem = menu.findItem(R.id.menuitemCompartilhar);
        mShareActionProvider = (ShareActionProvider)
                MenuItemCompat.getActionProvider(shareItem);
        mShareActionProvider.setShareIntent(getDefaultIntent());

        return super.onCreateOptionsMenu(menu);
    }

    private Intent getDefaultIntent() {

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, "text to share");
        return intent;

    }
}

Upvotes: 4

Views: 874

Answers (1)

Crawler
Crawler

Reputation: 2018

Your menu items is shown in popup list rather than dropdown. Well I want to inform you that this is not fault of your coding. Rather it is android.support.v7, that make such display for low end devices but works fine in high end devices. And I'm sorry to say that you can't do anything about it.

But if you want to have same dropdown effect for your app in all android devices, you must switch to ActionBarSherlock. It is great opensource library and provides consistent and unbiased result for all devices in action bar designing.

EDIT: Though ActionBarSherlock is awesome, its update has been stopped. Also, from API level 21 ActionBarActivity is now deprecated. For account android version are updating is good pace and world are preferring Material Design for mobile apps. I would like to advise two choices:

  1. Use official AppCompatActivity.
  2. Or replace your ActionBar with ToolBar tutorial, which is highly customisable.

Upvotes: 3

Related Questions