【问题标题】:Menu of sherlock ActionBar in Fragment not showing icon片段中夏洛克 ActionBar 的菜单未显示图标
【发布时间】:2015-04-23 19:46:36
【问题描述】:

任何人都可以帮助我解决 Sherlock 操作栏中的图标未显示问题。我想显示菜单,如:图标标题。但是,我从类似问题的答案中尝试了很多方法,它仍然只在菜单中显示标题,没有图标。

这里是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>

这是片段中的代码:

@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);
    }

谁能告诉我为什么?非常感谢=)

【问题讨论】:

  • 您可以尝试更改orderInCategory 的值吗?而不是保持不变?

标签: android android-fragments menu icons actionbarsherlock


【解决方案1】:

我不使用 Sherlock,也不会推荐它。

  1. 但是,我发现 Google 文档说您应该在出现 onCreateOptionsMenu 之前调用 setHasOptionsMenu(true)。网页@onCreateOptionsMenu 。方法 setHasOptionsMenu 可以在 OnCreate() 中调用。

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

  3. 可能图标格式不正确。要进行故障排除,请尝试使用以 @android:drawable

  4. 开头的标准图标

【讨论】:

  • 谢谢回复,我把sherlock改成v7了,EditText的颜色变成了白色。背景为白色,因此不会看到用户输入的文本。你对这个问题有什么想法吗?谢谢
  • @Maggie,你在布局中使用 android:textColor 吗?布局在哪里,和你发布的一样吗?
  • 嗯,不,上面这就像另一个问题。我将 Sherlock 更改为 v7,在 editText 中出现文本颜色问题。并且对于图标不显示的问题,仍然会发生。是的,我在 onCreateOptionsMenu 之前有 setHasOptionsMenu(true)。我有一个菜单,但没有图标,只有文字。
  • 我刚刚注意到您的 showAsAction="never" 设置,将其更改为“始终”以进行测试。我编辑了答案并添加了尝试 #1、2 和 3。
  • 感谢您的提问。我创建了一个新的 Android 项目并重写了所有内容。仍然不知道如何解决问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-21
相关资源
最近更新 更多