Search code examples
androidandroid-fragmentsmenuiconsactionbarsherlock

Menu of sherlock ActionBar in Fragment not showing icon


Anyone could help my with the icon not showing issue in sherlock Actionbar. I want to show the menu like: icon title. However, I try many ways from the answers of the similar question, it still only shows the title in the menu, no icons.

Here is the xml code:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.my.tab">

    <item
        android:id="@+id/action_addphoto"
        android:icon="@drawable/photo_icons"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="Photo"
        />
    <item
        android:id="@+id/action_addvideo"
        android:icon="@drawable/video_icons"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="Video"
        />
    <item
        android:id="@+id/action_addtext"
        android:icon="@drawable/text_icons"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="Text"
        />
</menu>

Here is the code in the Fragment:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    View view = inflater.inflate(R.layout.fragment_fragment_news_feed, null);
    setOverflowShowingAlways();

    dm = getResources().getDisplayMetrics();
    ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
    tabs = (PagerSlidingTabStrip) view.findViewById(R.id.tabs);
    pager.setAdapter(new MyPagerAdapter(getActivity().getSupportFragmentManager()));
    tabs.setViewPager(pager);
    setTabsValue();

    return view;

}
public void onCreateOptionsMenu (Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.myprofilesettinfs, menu);
    }

Could anyone tell me why? Thank you so much =)


Solution

  • I don't use Sherlock, and won't recommend it.

    1. However, I found Google documentation that says you should call setHasOptionsMenu(true) before onCreateOptionsMenu occurs. Webpage @ onCreateOptionsMenu . Method setHasOptionsMenu can be called in OnCreate().

    2. Another, set android:showAsAction="always" OR "ifRoom".

    3. Perhaps the icon is not formatted correctly. For troubleshooting, try the standard icons starting with @android:drawable