在网上找到的答案基本都是在TabLayout的xml中添加属性:app:tabBackground="@android:color/transparent",可是并没有生效。通过看源码找到的答案:
TabLayout.Tab tab = tablayout.newTab().setTag(i).setText(abbList.get(i)); LinearLayout layout = tab.view; layout.setBackgroundColor(ContextCompat.getColor(getActivity() , R.color.transparent)); tablayout.addTab(tab);