6

में TabIndicater का रंग बदलने के मैं इस प्रकार एक android.support.v4.view.PagerTabStrip एक्सएमएल में परिभाषित किया गया है:कैसे PagerTabStrip

<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_parent" 
    android:layout_height="match_parent" 
    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_parent" 
     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> 

मैं TabIndicater रंग कैसे बदल सकता हूँ? इसे setTabIndicatorColor(int color) द्वारा प्रोग्रामेटिकल बदल दिया जा सकता है लेकिन मुझे इसे xml में करने का कोई तरीका ढूंढना होगा।

उत्तर

9

मुख्य विधि एक वर्ग PagerTabStrip फैली हुई है, उदाहरण के लिए बनाने के लिए है, वर्ग 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(); 
    } 

} 
रेस में

/मूल्यों फ़ोल्डर नई attrs.xml, इस फ़ाइल की सामग्री नाम की एक फ़ाइल है:

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

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

एक ही फ़ोल्डर, एक फाइल नई नहीं तो मौजूद है, styles.xml नाम है, फाइल में नीचे दिए गए कोड डाल:

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

अंत में, अपने लेआउट xml फ़ाइल है:

<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_parent" 
android:layout_height="match_parent" 
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_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="top" 
    android:background="#33b5e5" 
    android:textColor="#fff" 
    android:paddingTop="4dp" 
    android:paddingBottom="4dp" /> 

+0

क्या मुझे कुछ याद आया? के लिए शैली/पेजर क्या है? आपने इसका बिल्कुल उपयोग नहीं किया। – nevermind