Fragment ActionBar Item将不会显示

时间:2016-02-09 01:44:43

标签: android android-fragments android-actionbar

我有一个标签片段,带抽屉,我试图强制显示ActionBar按钮。目前,它被推到溢出菜单......

如何将项目配置为始终显示在操作栏中?

enter image description here

片段:

IDisposable

菜单:

public class EventsTabFragment extends Fragment {

    public static TabLayout tabLayout;
    public static ViewPager viewPager;
    public static int int_items = 3;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        /**
         *Inflate tab_layout and setup Views.
         */
        View x = inflater.inflate(R.layout.tab_layout, null);
        tabLayout = (TabLayout) x.findViewById(R.id.tabs);
        viewPager = (ViewPager) x.findViewById(R.id.viewpager);

        /**
         *Set an Apater for the View Pager
         */
        viewPager.setAdapter(new MyAdapter(getChildFragmentManager()));

        /**
         * Now , this is a workaround ,
         * The setupWithViewPager dose't works without the runnable .
         * Maybe a Support Library Bug .
         */

        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                tabLayout.setupWithViewPager(viewPager);
            }
        });

        setHasOptionsMenu(true);

        return x;

    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.events_menu, menu);
    }

    class MyAdapter extends FragmentPagerAdapter {

        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        /**
         * Return fragment with respect to Position .
         */

        @Override
        public Fragment getItem(int position) {

            //  Need to build
            //  Order/first appearing will be specific to time of day, ie. if in morning, then breakfast/brunch, if midday then lunch, late then dinner
            switch (position) {
                case 0:
                    return new BreakfastFragment();  //   ChatActivity();
                case 1:
                    return new BreakfastFragment();
                case 2:
                    return new UpdatesFragment();
            }

            return null;
        }

        @Override
        public int getCount() {

            return int_items;

        }


        /**
         * This method returns the title of the tab according to the position.
         */

        @Override
        public CharSequence getPageTitle(int position) {

            //  Order/first appearing will be specific to time of day, ie. if in morning, then breakfast/brunch, if midday then lunch, late then dinner
            switch (position) {
                case 0:
                    return "Upcoming";
                case 1:
                    return "Invited";
                case 2:
                    return "Past";
            }
            return null;
        }
    }

}

1 个答案:

答案 0 :(得分:0)

你在哪里给工具栏充气?

docker stats

这有什么不同吗?在我停止使用setSupportActionBar()后,我不得不像上面代码中的工具栏对象那样给菜单充气,以使其工作。