gpt4 book ai didi

Android 如何从 TabLayout 隐藏选项卡

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:15:22 25 4
gpt4 key购买 nike

我需要隐藏第一个标签。第一页应该可以工作,但是当用户选择它时,它应该看起来像是在选项卡上被选中了。我该怎么做?

我用 TabHost 找到了一些解决方案,但对我没用。

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 隐藏选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33145645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com