How to change selected Tab Text color using TabLayout from code in Android?

后端 未结 8 912
悲哀的现实
悲哀的现实 2020-12-13 01:58

\"enter

I\'m using android.support.widget.TabLayout

8条回答
  •  伪装坚强ぢ
    2020-12-13 02:26

    Using native android code you can chage multiple tab background & text color

    LinearLayout tabsContainer = (LinearLayout) tabLayout.getChildAt(0);
            for (int i = 0; i < tabLayout.getTabCount(); i++) {
                for (int j = 0; j <= selectedTab.size(); j++) {
                    if (selectedTab.contains(section)) {
                        LinearLayout item = (LinearLayout) tabsContainer.getChildAt(section - 1);
                        TextView tv = (TextView) item.getChildAt(1);
                        item.setBackgroundColor(getResources().getColor(R.color.color00DF4C));
                        tv.setTextColor(getResources().getColor(R.color.colorWhite));
                    }
                }
            }
    

提交回复
热议问题