我使用的标签布局,这里是我的代码删除TabLayout左右填充
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="center"
app:tabMode="fixed"
android:minHeight="?attr/actionBarSize"
app:tabTextColor="#000"
app:tabSelectedTextColor="#fff"
app:tabIndicatorColor="@android:color/white"
android:clipToPadding="false"
/>
添加标签这样
//创建标签
的TextView标签=(TextView的)LayoutInflater。 from(this).inflate(R.layout.custom_tab,null); tab.setText(“Home”); tab.setCompoundDrawablesWithIntrinsicBounds(0,R.mipmap.ic_home_black_24dp,0,0); tabLayout.addTab(tabLayout.newTab()。setCustomView(tab));
TextView tab2 = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tab2.setText("Report");
tab2.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_trending_up_black_24dp, 0, 0);
tabLayout.addTab(tabLayout.newTab().setCustomView(tab2));
TextView tab3 = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tab3.setText("Medicine");
tab3.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_home_black_24dp, 0, 0);
tabLayout.addTab(tabLayout.newTab().setCustomView(tab3));
TextView tab4 = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tab4.setText("More");
tab4.setCompoundDrawablesWithIntrinsicBounds(0, R.mipmap.ic_trending_up_black_24dp, 0, 0);
tabLayout.addTab(tabLayout.newTab().setCustomView(tab4));
,这里是我的手机屏幕截图
https://i.stack.imgur.com/kYNs1.png
两件事 我1.How可以去除左和标签布局的右侧,其正在采取的空间?
我2.How可以更改活动和非活动标签的文字和图标的颜色
使用app:tabPadding属性 –