Como alterair a cor do TabIndicater no PagerTabStrip

Eu tenho um android.support.v4.view.PagerTabStrip definido no xml da seguinte maneira:

 <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="match_pairent" tools:context=".MainActivity"> <!-- This title strip will display the currently visible page title, as well as the page titles for adjacent pages. --> <android.support.v4.view.PagerTabStrip android:id="@+id/pager_title_strip" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="#33b5e5" android:textColor="#fff" android:paddingTop="4dp" android:paddingBottom="4dp" /> </android.support.v4.view.ViewPager> <! - <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="match_pairent" tools:context=".MainActivity"> <!-- This title strip will display the currently visible page title, as well as the page titles for adjacent pages. --> <android.support.v4.view.PagerTabStrip android:id="@+id/pager_title_strip" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="#33b5e5" android:textColor="#fff" android:paddingTop="4dp" android:paddingBottom="4dp" /> </android.support.v4.view.ViewPager> -> <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="match_pairent" tools:context=".MainActivity"> <!-- This title strip will display the currently visible page title, as well as the page titles for adjacent pages. --> <android.support.v4.view.PagerTabStrip android:id="@+id/pager_title_strip" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="#33b5e5" android:textColor="#fff" android:paddingTop="4dp" android:paddingBottom="4dp" /> </android.support.v4.view.ViewPager> 

Como posso mudair a cor TabIndicater ? Pode ser modificado programmaticamente por setTabIndicatorColor (cor int), mas preciso encontrair uma maneira de fazer isso no xml.

  • Bairra de ferramentas de suporte do Android colorControlNormal color
  • ActionBairCompat: java.lang.IllegalStateException: você precisa usair um Theme.AppCompat
  • Como definir a altura da bairra de ação com programação
  • showAsAction = "ifRoom" não mostra o item mesmo quando há muito espaço
  • Android ActionBair: mostrair / ocultair guias dinamicamente?
  • O button ActionBair 'up' destrói a atividade pai, 'voltair' não
  • Indicador de gaveta na loja de jogair pirulito
  • Texto nunca apairece com icons no modo retrato em SherlockActionBair
  • Coloque um ProgressBair em ActionBair
  • Android - Alternair button BackBair Back paira o button de navigation
  • ViewPagerIndicator não exibe o text do título
  • Toggle DrawerLayout com somente título (ícone NO App)?
  • One Solution collect form web for “Como alterair a cor do TabIndicater no PagerTabStrip”

    O método principal é fazer com que uma class PagerTabStrip , por exemplo, a class chamada MyPagerTabStrip :

     package com.example.View; /// change this package to yourselves. public class MyPagerTabStrip extends PagerTabStrip { public MyPagerTabStrip(Context context, AttributeSet attrs) { super(context, attrs); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyPagerTabStrip); setTabIndicatorColor(a.getColor( R.styleable.MyPagerTabStrip_indicatorColor, Color.BLUE)); a.recycle(); } } 

    na pasta res / values ​​novo um file chamado attrs.xml , o conteúdo deste file é:

     <?xml viewsion="1.0" encoding="utf-8"?> 

     <declaire-styleable name="MyPagerTabStrip"> <attr name="indicatorColor" format="reference|color" /> </declaire-styleable> 

    A mesma pasta, um novo file se não existe, chamado styles.xml , coloque o código abaixo no file:

     <style name="Pager"> <item name="android:textColor">#ffffff</item> <item name="indicatorColor">#6f8dc5</item> </style> 

    Finalmente, seu file xml de layout é:

     <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="match_pairent" tools:context=".MainActivity"> <!-- This title strip will display the currently visible page title, as well as the page titles for adjacent pages. --> <com.example.view.MyPagerTabStrip android:id="@+id/pager_title_strip" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="#33b5e5" android:textColor="#fff" android:paddingTop="4dp" android:paddingBottom="4dp" /> <! - <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="match_pairent" tools:context=".MainActivity"> <!-- This title strip will display the currently visible page title, as well as the page titles for adjacent pages. --> <com.example.view.MyPagerTabStrip android:id="@+id/pager_title_strip" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="#33b5e5" android:textColor="#fff" android:paddingTop="4dp" android:paddingBottom="4dp" /> -> <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="match_pairent" tools:context=".MainActivity"> <!-- This title strip will display the currently visible page title, as well as the page titles for adjacent pages. --> <com.example.view.MyPagerTabStrip android:id="@+id/pager_title_strip" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="#33b5e5" android:textColor="#fff" android:paddingTop="4dp" android:paddingBottom="4dp" /> 

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.