How to change tab indicator color

I am new to Android , and before starting programming, I found that many applications now use Snippets, especially the Scroll List Tab

How to change the Tab indicator / highlight color (I googled and changed the color of the ActionBar to RED programmatically), but I don’t know how to change the color of the Tab indicator to RED. (software priority)

my actionbar looks like this

I use the lines below to change the background color of the ActionBar , but I also need to programmatically change the color of the tab indicator.

actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED));
+4
source share
4
+2

setIcon(R.drawable.ic_icon_name_here)

, Android?

0

- ( " ", ).

drawable tab_selector.xml :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/tab_selected_pink" />
    <item android:state_selected="false" android:drawable="@drawable/tab_unselected_white" />
</selector>

values/styles.xml, , - :

<style name="AppTheme" parent="Theme.AppCompat.Light">
     <item name="android:actionBarTabBarStyle">@style/MyTabStyle</item>
</style>

<style name="MyTabStyle" parent="android:Widget.ActionBar.TabBar">
    <item name="android:background">@drawable/tab_indicator_selector</item>
</style>

, item name attribute parent attribute . .

, . , , 9patch drawables, .

Jake Wharton ViewPagerIndicator, .

0

Source: https://habr.com/ru/post/1527442/


All Articles