少年意气强不羁,虎胁插翼白日飞。这篇文章主要讲述android TabLayout 相关相关的知识,希望能为你提供帮助。
1.
TabLayout 设置 指示条 颜色、高度,字体颜色大小等
< android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:background="@color/colorAccent"
android:layout_gravity="top"
app:tabIndicatorColor="@color/colorBlue"
app:tabIndicatorHeight="10dp"
app:tabSelectedTextColor="@color/colorBlue"
app:tabTextAppearance="@style/MyTabLayoutText"
app:tabTextColor="@color/black" />
添加style
< style name="MyTabLayoutText" parent="TextAppearance.Design.Tab">
< item name="android:textSize"> 40sp< /item>
< /style>
2.TabLayout 添加tab方法
mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
mTabLayout.addTab(mTabLayout.newTab().setText(ResourcesUtil.getString(
this, R.string.txt_to_send_title)).setTag(TAG_TO_SEND));
mTabLayout.addTab(mTabLayout.newTab().setText(ResourcesUtil.getString(
this, R.string.txt_wonderful_review)).setTag(TAG_SEND_REVIEW));
mTabLayout.addOnTabSelectedListener(this);
【android TabLayout 相关】3.TabLayout 设置子item margin值方法
public void setTabItem(@NonNull final TabLayout tabLayout, int marginRight) {
LogUtil.d(TAG + "setTabItem 000 tabLayout:" + tabLayout);
tabLayout.post(new Runnable() {
@Override
public void run() {
try {
LogUtil.d(TAG + "setTabItem 111");
//Get the mtabstrip property of tablayout.
Field tabStripField = tabLayout.getClass().getDeclaredField("mTabStrip");
tabStripField.setAccessible(true);
LinearLayout tabStrip = (LinearLayout) tabStripField.get(tabLayout);
int count = tabStrip.getChildCount();
for (int i = 0; i < count; i++) {
View tabView = tabStrip.getChildAt(i);
//Get the mtextview property of tabview.
Field textViewField = tabView.getClass().getDeclaredField("mTextView");
textViewField.setAccessible(true);
TextView textView = (TextView) textViewField.get(tabView);
tabView.setPadding(0, 0, 0, 0);
//Because I want the effect to be as wide as the line is,
// measure the width of mtextview.
int width = textView.getWidth();
if (width == 0) {
textView.measure(0, 0);
width = textView.getMeasuredWidth();
}
//Set the space between the left and right of the tab.Note that padding
// cannot be used here, because the width of the centerline in the
// source code is set according to the width of the tabview
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)
tabView.getLayoutParams();
params.width = width; //The width of the indicator bar is set here.
//params.leftMargin = margin;
LogUtil.d(TAG + "setTabItem 222 marginRight:" + marginRight);
if (i < count - 1) {
params.rightMargin = marginRight;
}
//params.bottomMargin = marginBottom;
tabView.setLayoutParams(params);
tabView.invalidate();
}
} catch (NoSuchFieldException e) {
LogUtil.d(TAG + "setTabItem 333 error:" + e);
e.printStackTrace();
} catch (IllegalAccessException e) {
LogUtil.d(TAG + "setTabItem 444 error:" + e);
e.printStackTrace();
}
}
});
}
推荐阅读
- adb shell am force-stop杀不死某些app的原因
- Android单元测试
- hutool的定时器如何读取application文件
- 项目填坑记录—SenseAR发布到安卓手机相机打开不了
- uniapp使用echart
- Selenium WebDriver与Selenium RC详细介绍
- Selenium WebDriver-滚动网页示例
- Selenium WebDriver-在IE浏览器上运行测试
- Selenium WebDriver-Firefox浏览器运行测试-Gecko驱动程序