要設置Android SlidingTabLayout的樣式,可以通過以下步驟進行:
<style name="CustomSlidingTabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">@color/indicator_color</item>
<item name="tabTextAppearance">@style/CustomTabTextAppearance</item>
</style>
<style name="CustomTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textColor">@color/text_color</item>
</style>
<com.google.android.material.tabs.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CustomSlidingTabLayout"/>
SlidingTabLayout slidingTabLayout = findViewById(R.id.sliding_tabs);
for (int i = 0; i < slidingTabLayout.getTabCount(); i++) {
TabLayout.Tab tab = slidingTabLayout.getTabAt(i);
if (tab != null) {
tab.setCustomView(R.layout.custom_tab_view);
}
}
通過以上步驟,可以很容易地設置Android SlidingTabLayout的樣式。您可以根據自己的需求,定義不同的樣式,以滿足設計要求。