我正在开发一个应用程序,需要用到选项卡。因此,我最终选择了选项卡布局,并包含了几个选项卡。代码如下:
private void setupNavTab() {
int[][] states = new int[][]{
new int[]{android.R.attr.state_selected},
new int[]{-android.R.attr.state_selected},
new int[]{-android.R.attr.state_enabled}
};
int[] colors = new int[]{
ContextCompat.getColor(getActivity(), R.color.cricut_selected_green),
ContextCompat.getColor(getActivity(), R.color.nav_bar_unselected_content),
ContextCompat.getColor(getActivity(), R.color.edit_button_text_color_inactive)
};
ColorStateList cslist = new ColorStateList(states, colors);
if (tabs != null) {
tabs.removeAllTabs();
tabs.setTabTextColors(cslist);
firstTab = tabs.newTab().setTag(TAB_FIRST);
View customFirstTabView = LayoutInflater.from(getActivity()).inflate(R.layout.tab_item_layout, null, false);
firstTabView = (TextView) customFirstTabView.findViewById(R.id.textContainer);
firstTabView.setText(R.string.first);
firstTabView.setTextColor(cslist);
firstTab.setCustomView(customFirstTabView);
secondTab = tabs.newTab().setTag(TAB_SECOND);
View customSecondView = LayoutInflater.from(getActivity()).inflate(R.layout.tab_item_layout, null, false);
secondTabView = (TextView) customSecondView.findViewById(R.id.textContainer);
secondTabView.setText(R.string.second);
secondTabView.setTextColor(cslist);
secondTab.setCustomView(customSecondView);
thirdTab = tabs.newTab().setTag(TAB_THIRD);
View customThirdTabView
= LayoutInflater.from(getActivity()).inflate(R.layout.tab_item_layout, null, false);
thirdTabView = (TextView) customThirdTabView.findViewById(R.id.textContainer);
thirdTabView.setText(R.string.third);
thirdTabView.setTextColor(cslist);
thirdTab.setCustomView(customThirdTabView);
tabs.addTab(firstTab, true);
tabs.addTab(secondTab, false);
tabs.addTab(thirdTab, false);
}
}
我没有使用ViewPager。 在这里,用户应该在完成第一个选项卡和第二个选项卡中的必要步骤之前无法访问第三个选项卡。是否有一种方法在用户完成这些步骤之前禁用第三个选项卡?