0

ViewPager에서 PagerTitleStrip을 사용하고 있습니다.PagerTitleStrip에 2 가지 다른 텍스트 색상을 사용하는 방법은 무엇입니까?

<android.support.v4.view.ViewPager 
    android:id="@id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

    <android.support.v4.view.PagerTitleStrip 
     android:id="@id/pager_title_strip" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     style="@style/PagerTitleStrip" 
     /> 
</android.support.v4.view.ViewPager> 

이 스트립에 n 개의 제목을 표시해야합니다.

final int titles[] = {"Title1" , "Title2", "Title3", "Title4"}; 

다음은 PagerTitleStrip에 적용된 스타일입니다.

<style name="PagerTitleStrip"> 
    <item name="android:textColor">@color/red</item> 
    <item name="android:background">@android:color/white</item> 
    <item name="android:textSize">20sp</item> 
</style> 

이 ViewGroup의 AttributeSet에는 textColor 필드가 하나만 있습니다.

보이는 페이지의 제목 (기본 제목)과 보이지 않는 페이지 (가장자리에 부분적으로 표시되는 기본 제목이 아닌)의 두 가지 색상 (빨간색과 회색)을 설정하고 싶습니다.

또한 페이지를 변경하는 동안 스트립 제목이 전환 중에 색상이 변경되어야합니다.

문서 당 은 기본 제목이 아닌 제목에 대해 알파 값을 정의 할 수있게 해줍니다. 대신 다른 텍스트 색상을 사용하고 싶습니다. 아무도 도와 줄 수 있습니까? 당신은 XML을 통해 그것을 할 수

+0

잘 모르겠지만 선택기를 통해 텍스트 색상을 설정할 수 있습니다. 당신은 당신을 위해 일하는 주를 시도 할 수 있습니다. 행운을 빕니다. –

+0

그것은 단순히 불가능합니다. 이런 식으로하고 싶다면 PagerTitleStrip을 직접 구현해야합니다. – reVerse

+0

@hbansal 어떤 해결책을 찾았습니까? 저에게 알려주세요. – AB1209

답변

2

, 당신이해야 할 유일한 것은 쓰기 색상 상태 목록입니다

pager_tab_strip_text_selector.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:color="@color/background_black_3" android:state_window_focused="false" /> 
    <item android:color="@color/highlight_gold" android:state_window_focused="true" /> 

</selector> 

는 스타일 내부 색상 상태 목록을 넣어 :

<style name="PagerTabStrip"> 
     <item name="android:textColor">@color/pager_tab_strip_text_selector</item> 
    </style> 

당신이해야하는 유일한 작업은 스타일로 설정하는 대신 다음과 같이 textAppearance로 설정하는 것입니다.

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

     <android.support.v4.view.PagerTitleStrip 
      android:id="@+id/fragment_light_pagertabstrip" 
      android:textAppearance="@style/PagerTabStrip.Light" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/transparent" /> 

    </android.support.v4.view.ViewPager> 
관련 문제