本文介绍了支持设计库自定义新TabLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI我试图将图像添加到支持Android的设计引入的新TabLayout。不过,这并不似乎是工作我花了一些code github上,并试图做除了文本没有一些小的变化干活没有图标是显示THA选项卡,而不是文字上。
HI i am trying to add image to the new TabLayout introduced in android support design. But it doesn't seems to be working i took some code github and tried to do some little change except for text nothing is workin no icon is showing on tha tab instead of text.
任何帮助是AP preciated。
Any help is appreciated.
List<String> titles = new ArrayList<>();
titles.add("Page One");
titles.add("Page Two");
mTabLayout.addTab(mTabLayout.newTab().setIcon(getResources().getDrawable(R.drawable.ic_launcher)));
mTabLayout.addTab(mTabLayout.newTab().setIcon(getResources().getDrawable(R.drawable.ic_launcher)));
List<Fragment> fragments = new ArrayList<>();
fragments.add(new AnimatedFragment());
fragments.add(new AnimatedFragment());
FragmentAdapter adapter =
new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
viewPager.setAdapter(adapter);
viewPager.setOffscreenPageLimit(0);
mTabLayout.setupWithViewPager(viewPager);
mTabLayout.setTabsFromPagerAdapter(adapter);
这是code,其中我安装tablayout和viewpager。
This is the code where i setup tablayout and viewpager.
推荐答案
您可以添加图标从viewPager的getPageTitle方法tablayout。这里是一个很好的教程做让我尝试。
You can add icons to tablayout from viewPager's getPageTitle method. Here is a good tutorial tutorial to do so that I tried.
这篇关于支持设计库自定义新TabLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!