【发布时间】:2017-02-22 06:11:49
【问题描述】:
我正在使用标签布局,这是我的代码
<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("首页"); 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.如何去除tab布局左右占用的空间?
2.如何更改活动和非活动选项卡的文本和图标颜色
【问题讨论】:
-
使用 app:tabPadding 属性