简体   繁体   English

片段中的sherlock ActionBar菜单未显示图标

[英]Menu of sherlock ActionBar in Fragment not showing icon

Anyone could help my with the icon not showing issue in sherlock Actionbar. 任何人都可以通过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: 这是xml代码:

<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 =) 非常感谢你=)

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. 但是,我发现Google文档说您应该在onCreateOptionsMenu发生之前调用setHasOptionsMenu(true) Webpage @ onCreateOptionsMenu . 网页@ onCreateOptionsMenu Method setHasOptionsMenu can be called in OnCreate(). 可以在OnCreate()中调用setHasOptionsMenu方法。

  2. Another, set android:showAsAction="always" OR "ifRoom" . 另一个,设置android:showAsAction="always""ifRoom"

  3. Perhaps the icon is not formatted correctly. 图标可能格式不正确。 For troubleshooting, try the standard icons starting with @android:drawable 要进行故障排除,请尝试以@android:drawable开头的标准图标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM