我在片段中使用ViewPager。 viewpager包含三个片段。当我回到这个片段时,我的问题是我得到了一个空白片段。内部工作正常。
我的代码正在关注
private void setupViewPager(ViewPager viewPager) {
adapter = new ViewPagerAdapter(getActivity().getSupportFragmentManager());
//adapter.addFragment(new DiscoverFragment(), "Discover");
adapter.addFragment(new TimelineFragment(), getString(R.string.home_nav));
adapter.addFragment(new DiscoverNewFragment(), getString(R.string.discover));
adapter.addFragment(new ServiceFragment(), getString(R.string.service));
viewPager.setAdapter(adapter);
}
private void setupTabIcons() {
TextView tabOne = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.custom_tab, null);
tabOne.setText(getString(R.string.home_nav));
tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_binoculars, 0, 0);
tabLayout.getTabAt(0).setCustomView(tabOne);
TextView tabThree = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.custom_tab, null);
tabThree.setText(getString(R.string.discover));
tabThree.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_group, 0, 0);
tabLayout.getTabAt(1).setCustomView(tabThree);
TextView tabTwo = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.custom_tab, null);
tabTwo.setText(getString(R.string.service));
tabTwo.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_bell, 0, 0);
tabLayout.getTabAt(2).setCustomView(tabTwo);
}