Đây là những gì bạn cần làm:
Tạo một Style cho ứng dụng của bạn: Ở đây tôi đang tùy chỉnh Thanh tab và văn bản của nó (Tôi đang sử dụng chủ đề tương thích cơ sở nhưng bạn có thể sử dụng HOLO hoặc bất kỳ thứ gì bạn thích):
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarTabTextStyle">@style/TabTextStyle</item>
<item name="android:actionBarTabStyle">@style/TabBarStyle</item>
<!-- Support library compatibility (ActionBarCompat) -->
<item name="actionBarTabTextStyle">@style/TabTextStyle</item>
<item name="actionBarTabStyle">@style/TabBarStyle</item>
</style>
Tạo những phong cách:
<style name="TabTextStyle" parent="@style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">@color/ab_tab_txt</item>
</style>
<style name="TabBarStyle" parent="@style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">@drawable/tab_indicator</item>
</style>
Đối với màu sắc và drawables, bạn có thể tạo một selector cho phép các tab để thay đổi dựa trên nhấp chuột và lựa chọn:
File: res/màu/ab_tab_txt (tôi đang sử dụng tập tin màu sắc từ res/values để thiết lập các hằng số của tôi, nhưng bạn có thể đặt màu sắc như vậy: #fff)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@color/ab_tab_txt_selected"/>
<item android:color="@color/ab_tab_txt_unselected"/>
</selector>
file res/drawable/tab_indicator
<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/tab_selected_example" />
<!-- Focused states -->
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_unselected_focused_example" />
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_selected_focused_example" />
<!-- Pressed -->
<!-- Non focused states -->
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="true"
android:drawable="@drawable/tab_unselected_pressed_example" />
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="true"
android:drawable="@drawable/tab_selected_pressed_example" />
<!-- Focused states -->
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="true"
android:drawable="@drawable/tab_unselected_pressed_example" />
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="true"
android:drawable="@drawable/tab_selected_pressed_example" />
</selector>
file drawable của tôi là NinePatches mà tôi tạo sử dụng công cụ này hữu ích: http://jgilfelt.github.io/android-actionbarstylegenerator/
Bạn vẫn còn ở đó? –
oh xin lỗi, quên chấp nhận. Đề xuất của bạn hoạt động, cảm ơn – Droidman