Disable Tabs in TabLayout
You can create a util function, my fun in Kotlin:
fun disableTabAt(tablayout: TabLayout?, index: Int) {
(tablayout?.getChildAt(0) as? ViewGroup)?.getChildAt(index)?.isEnabled = false
}
When you want do something with a view, you can debug or click in parent view to know how it's created. By this way you can do anything that you want. For this case, you can go to Tablayout class to understand.
Another trick:
You can put another blank transparent view upon tablayout until your requirement fulfill. When you need to enable/show the tabs then just hide the blank view.
To enable specific tab at position :
LinearLayout tabStrip = ((LinearLayout)tabLayout.getChildAt(0));
tabStrip.getChildAt(position).setOnTouchListener((v,event)->false);
To disable the tab at position :
tabStrip.getChildAt(position).setOnTouchListener((v,event)->true);
there are 3 methods implemented by the tab click listener, one of them is onTabSelected() put a boolean condition to check if your fragment is initialised. Then if that condition is satisfied then allow transaction to take place. Also initialize the tabs after your fragment code