导航栏显示的图片 和 导航TAB下的横线颜色 ,可以在自定义的style中设置tabIndicatorColor来决定,如果要显示TAB,textAllCaps需要设置为false。如下所示
<!--修改默认的TabLayout取的 tab indicator color chosen is the accent color defined for your Material Design theme--> <style name="MyCustomTabLayout" parent="Widget.Design.TabLayout"> <item name="tabIndicatorColor">#0000FF</item> <!--必须设置textAllCaps为false,否则图片不显示--> <item name="tabTextAppearance">@style/MyCustomTextAppearance</item> </style> <!--By default, the tab created by TabLayout sets the textAllCaps property to be true, which prevents ImageSpans from being rendered. You can override this behavior by changing the tabTextAppearance property.--> <style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab"> <item name="textAllCaps">false</item> </style>1
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
如果要将TAB放在底部,只需要在主布局文件LinearLayout中将TabLayout放在下面即可
ViewPager 我们引用的是V4包下的,以实现更好地兼容,这样的话 就需要使用getSupportFragmentManager来获取FragmentManager
TabLayout设置TabMode为TabLayout.MODE_FIXED,防止TAB挤在一起