我有Tab布局,其中有两个TabItems。因此,当选择一个tabitem时,下划线来自起点,宽度太大。 所以我想根据我的标签文本设置指标宽度,并仅在两个标签项中的文本下显示下划线。
答案 0 :(得分:0)
final TabLayout tabLayout = (TabLayout) view.findViewById(R.id.varietytaba);
tabLayout.addTab(tabLayout.newTab().setText("VEG"));
tabLayout.addTab(tabLayout.newTab().setText("NON VEG"));
tabLayout.setBackgroundColor(Color.parseColor("#000000"));
tabLayout.setTabTextColors(Color.parseColor("#FFFFFF"), Color.parseColor("#FFFFFF"));
final ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewPager_drinka);
viewPager.setAdapter(new Fragvariety.Pageradapter(getChildFragmentManager(),
tabLayout.getTabCount()));
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FFFFFF"));
}