Android如何从TabLayout隐藏选项卡 [英] Android how to hide tab from TabLayout
本文介绍了Android如何从TabLayout隐藏选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要隐藏第一个标签.第一页应该可以工作,但是当用户选择它时,应该看起来就像在选项卡上一样.我该怎么做?
I need to hide first tab. First page should work but when user select it, it should be seems like on tabs is selected. How I can do this?
我找到了TabHost的一些解决方案,但对我来说毫无用处.
I found some solutions with TabHost and it useless to me.
public class TabFragmentClients extends Fragment {
public static TabLayout tabLayout;
public static ViewPager viewPager;
public static int int_items = 5 ;
FinanceClients FinanceClients;
public ClientsFragment clientsFragment;
public FinanceFragment financeFragment;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
/**
*Inflate tab_layout and setup Views.
*/
final View x = inflater.inflate(R.layout.tab_layout_clients,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);
}
});
return x;
}
推荐答案
tabLayout = (TabLayout) findViewById(R.id.tabs);
((ViewGroup) tabLayout.getChildAt(0)).getChildAt(desiredPosition).setVisibility(View.GONE);//hides the tab
这篇关于Android如何从TabLayout隐藏选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文