2012-11-15 28 views
5

Tôi cần thay đổi màu phông chữ cho PagerTabStrip trong ViewPager cho ứng dụng Android của tôi. Đây là bố cục xml cho cùng một. Có cách nào tôi có thể làm điều này?Màu phông chữ tùy chỉnh cho PagerTabStrip trong ViewPager cho ứng dụng Android của tôi

<android.support.v4.view.ViewPager 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@id/head" 
    android:id="@+id/myfivepanelpager"> 

     <android.support.v4.view.PagerTabStrip 
     android:id="@+id/pgstrip" 
     android:layout_width="fill_parent" 
     android:background="@color/strip" 
     android:layout_height="@dimen/pagerstripht" 
     android:layout_gravity="top" 
     /> 

    </android.support.v4.view.ViewPager> 

Trả lời

10

Nếu bạn chưa phát hiện ra chưa, mã dưới

PagerTabStrip pagerTabStrip = (PagerTabStrip) findViewById(R.id.pager_title_strip); 
pagerTabStrip.setDrawFullUnderline(true); 
pagerTabStrip.setTabIndicatorColor(Color.RED); 
10

trong mã của bạn:

<android.support.v4.view.PagerTabStrip 
     android:id="@+id/pgstrip" 
     android:layout_width="fill_parent" 
     android:background="@color/strip" 
     android:layout_height="@dimen/pagerstripht" 
     android:layout_gravity="top" 
     /> 

Tôi nghĩ thêm android: Format = "# 000" sẽ thay đổi màu văn bản.

+3

Không chắc chắn tại sao câu trả lời này đã bị bỏ phiếu? Đặt thuộc tính 'textColor' thực sự thay đổi màu của văn bản trong một' PagerTabStrip'. –

+5

Nó thực sự làm việc !! Nhưng tôi không biết tại sao gợi ý Android không hiển thị tùy chọn cụ thể này –

10

Nhận chế độ xem con của PagerTabStrip và kiểm tra xem đó có phải là phiên bản của TextView hay không. Nếu đúng, hãy đặt màu văn bản:

PagerTabStrip mPagerTabStrip = (PagerTabStrip) findViewById(R.id.pgstrip); 
for (int i = 0; i < mPagerTabStrip.getChildCount(); ++i) { 
    View nextChild = mPagerTabStrip.getChildAt(i); 
    if (nextChild instanceof TextView) { 
     TextView textViewToConvert = (TextView) nextChild; 
     textViewToConvert.setTextColor(getResources().getColor(R.color.primary_text_color_dark_gray)); 
    } 
} 
+2

Tôi sẽ upvote này nếu có một chút giải thích cho mã. – Amicable

+3

Tôi đã cập nhật câu trả lời của mình. –

Các vấn đề liên quan