我有一个片段,它有一个标签布局和一个带有自定义适配器的viewpager 我想"灰色",并根据条件禁用某些标签项的点击。
我该如何实现?
答案 0 :(得分:0)
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.all)).setTag("-1"));
TabLayout.Tab tab = tabLayout.newTab();
View v = LayoutInflater.from(HomeActivity.this).inflate(R.layout.custom_tab, null);
TextView text1 = (TextView) v.findViewById(R.id.text1);
text1.setText(getString(R.string.all));
tab.setCustomView(v);
tabLayout.addTab(tab);
tabLayout.getTabAt(0).getCustomView().setSelected(true);
for (int i = 0; i < 5; i++) {
//Below code to add categories in Tab using Web Service
tab = tabLayout.newTab();
v = LayoutInflater.from(HomeActivity.this).inflate(R.layout.custom_tab, null);
tab.setTag(categoriesModel.getData().get(i).getBranch_id());
text1 = (TextView) v.findViewById(R.id.text1);
text1.setText(categoriesModel.getData().get(i).getName());
tab.setTag(categoriesModel.getData().get(i).getId());
if (categoriesModel.getData().get(i).isUnAvailable()) {
text1.setTextColor(ContextCompat.getColor(HomeActivity.this, R.color.color_font_deselect));
text1.setEnabled(false);
}
tab.setCustomView(v);
tabLayout.addTab(tab);
}