PagerIndicator主题样式修改
默认的黑色好丑 所以大家需要动手改造一下,
1 打开
Manifest.xml
<activity android:name="com.zb.zhihuianyang.MainActivity"
android:theme="@style/Theme.PageIndicatorDefaults"></activity>
2 Ctrl进入"@style/Theme.PageIndicatorDefaults"
<resources> <style name="Theme.PageIndicatorDefaults" parent="android:Theme"> <item name="vpiIconPageIndicatorStyle">@style/Widget.IconPageIndicator</item> <item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item> </style> <style name="Widget"> </style> <style name="Widget.TabPageIndicator" parent="Widget"> <item name="android:gravity">center</item> <item name="android:background">@drawable/vpi__tab_indicator</item> <item name="android:paddingLeft">22dip</item> <item name="android:paddingRight">22dip</item> <item name="android:paddingTop">12dp</item> <item name="android:paddingBottom">12dp</item> <item name="android:textAppearance">@style/TextAppearance.TabPageIndicator</item> <item name="android:textSize">16sp</item> <item name="android:maxLines">1</item> </style> <style name="TextAppearance.TabPageIndicator" parent="Widget"> <item name="android:textStyle">bold</item> <item name="android:textColor">@color/vpi__dark_theme</item> </style> <style name="Widget.IconPageIndicator" parent="Widget"> <item name="android:layout_marginLeft">6dp</item> <item name="android:layout_marginRight">6dp</item> </style> </resources>
其中 <item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item> 是tab的主题
<style name="Widget.TabPageIndicator" parent="Widget"> <item name="android:gravity">center</item> <item name="android:background">@drawable/vpi__tab_indicator</item> <item name="android:paddingLeft">22dip</item> <item name="android:paddingRight">22dip</item> <item name="android:paddingTop">12dp</item> <item name="android:paddingBottom">12dp</item> <item name="android:textAppearance">@style/TextAppearance.TabPageIndicator</item> <item name="android:textSize">16sp</item> <item name="android:maxLines">1</item> </style>
<item name="android:background">@drawable/vpi__tab_indicator</item> 背景
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Non focused states --> <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" /> <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/news_tab_item_bg_select" /> <!-- Focused states --> <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" /> <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/news_tab_item_bg_select" /> <!-- Pressed --> <!-- Non focused states --> <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@android:color/transparent" /> <item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/news_tab_item_bg_select" /> <!-- Focused states --> <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@android:color/transparent" /> <item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/news_tab_item_bg_select" /> </selector>
各种状态对应不同的图片
各种状态可以看我这篇
http://www.cnblogs.com/AceIsSunshineRain/p/5186330.html
文字在 <item name="android:textAppearance">@style/TextAppearance.TabPageIndicator</item> 里
<style name="TextAppearance.TabPageIndicator" parent="Widget"> <item name="android:textStyle">bold</item> <item name="android:textColor">@color/vpi__dark_theme</item> </style>
进入 vpi__dark_theme
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="false" android:color="#000"/> <item android:state_window_focused="false" android:color="#000"/> <item android:state_pressed="true" android:color="#f00"/> <item android:state_selected="true" android:color="#f00"/> <!--item android:state_activated="true" android:color="@color/vpi__bright_foreground_holo_dark"/--> <item android:color="#000"/> <!-- not selected --> </selector>
没焦点我都改黑了 选择按下都是红色