【问题标题】:Android disable a tab on a tablayoutAndroid禁用标签布局上的标签
【发布时间】:2016-12-09 11:16:27
【问题描述】:

我有一个片段,它有一个选项卡布局和一个带有自定义适配器的 viewpager 我想“变灰”,并根据条件禁用某些选项卡项的点击。

我该如何实现?

【问题讨论】:

    标签: android android-layout android-tabs android-tablayout


    【解决方案1】:
    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);
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 2021-05-13
      相关资源
      最近更新 更多