0

I want actionbar share provider in one of my activities, and i have Theme.Sherlock.Light.DarkActionBar as baseTheme.

Here is how i create share option on activity:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    ShareActionProvider provider = new ShareActionProvider(getSupportActionBar().getThemedContext());
    provider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
    provider.setShareIntent(createShareIntent());
    menu.add(Menu.NONE, SHARE_ACTION_ID, 0,
            getString(R.string.action_share))
            .setIcon(R.drawable.icon_share_white)
            .setActionProvider(provider)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    return super.onCreateOptionsMenu(menu);
}

private Intent createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, url);
    return shareIntent;
}

And this is my baseTheme:

<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.    

    -->
</style> 

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    <item name="actionBarItemBackground">@drawable/action_item_background_selector</item>
    <item name="android:actionBarItemBackground">@drawable/action_item_background_selector</item>
</style>

App works just fine with Theme.Sherlock but when i use my AppTheme it gives me this error:

FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1026)
at android.content.res.Resources.getDrawable(Resources.java:671)
at com.actionbarsherlock.widget.ShareActionProvider.onCreateActionView(ShareActionProvider.java:170)
at com.actionbarsherlock.internal.view.ActionProviderWrapper.onCreateActionView(ActionProviderWrapper.java:23)
at android.view.ActionProvider.onCreateActionView(ActionProvider.java:98)
at com.android.internal.view.menu.MenuItemImpl.getActionView(MenuItemImpl.java:580)
at com.android.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:264)
at com.android.internal.view.menu.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:555)
at com.android.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1048)
at com.android.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
at com.android.internal.view.menu.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:297)
at com.android.internal.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:244)
at com.android.internal.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:946)
at com.android.internal.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:969)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:498)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:829)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:3192)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)

I've seen lots of this kind of questions and their accepted responses but no luck.. Any idea how to fix this? Thanks in advance.

Edit: Removing "actionBarItemBackground" these attributes from AppTheme in style.xml also works, but i need actionbar to have a custom background as well... So what could be the solution for that?

yahya
  • 4,810
  • 3
  • 41
  • 58

1 Answers1

0

I don't have 50 reputation to comment so I'll answer it here.

This error:

Resources$NotFoundException: Resource ID #0x0

tells you that a style, or parent directive of a style cannot be resolved by Android at runtime. Check your styles.xml file again.

If you are using Eclipse, you can check the correctness of the name, parent, etc directives by pressing Left-click, or Ctrl+Left-click on each of the directive. If the clicked value is resolved, Eclipse will either move to another area within styles.xml, or open up a new stylesheet file.

UPDATE 1:

@yahya: "i use AppBase theme... so it works almost every activity but not just this one" Post the codes of the activity that's not working. Also, post your AndroidManifest.xml file.

  • Thanks but i use AppBase theme -you can see on question- as base theme, so it works almost every activity but not just this one. And when i change this activity's theme to Theme.Sherlock it works just fine... – yahya Apr 14 '14 at 14:00