2014-11-14 1 views
3

내 안드로이드 테마를 만들어 액션 바 탭의 모양을 변경했습니다. 문제는 텍스트 색상 선택기가 state_pressed 속성을 무시하는 것처럼 보이므로이 탭을 눌러도 탭 텍스트의 색상이 항상 동일합니다. 다른 상태에는 아무런 문제가 없습니다. 예를 들어 state_selected가 올바르게 인식되고 선택한 탭에는 선택되지 않은 탭 텍스트 색상과 다른 텍스트 색상이 있습니다.

무엇보다, 나는 또한 탭 배경에 대한 선택기를 만들었고 tab_pressed와 함께 작동합니다 (탭을 누를 경우 backround 색이 변경됨).Android 탭 텍스트 색상 선택기가 state_pressed를 무시합니다.

내 코드의 일부 조각이 있습니다

styles.xml :

<style name="Theme.MyTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
    <item name="android:actionBarTabStyle">@style/Theme.MyTheme.TabStyle</item> 
    <item name="android:actionBarTabTextStyle">@style/Theme.MyTheme.TabTextStyle</item> 
</style> 

... 

<style name="Theme.MyTheme.TabStyle" 
     parent="@android:style/Widget.Holo.Light.ActionBar.TabView"> 
    <item name="android:background">@drawable/background_selector</item> 
</style> 

<style name="Theme.MyTheme.TabTextStyle" 
     parent="@android:style/Widget.Holo.Light.ActionBar.TabText"> 
    <item name="android:textColor">@color/textcolor_selector</item> 
</style> 

background_selector.xml :

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_selected="false" android:state_pressed="false"> 
     <shape> 
      <solid android:color="#00ff00"/> 
     </shape> 
    </item> 

    <item android:state_selected="false" android:state_pressed="true"> 
     <shape> 
      <solid android:color="#0000ff"/> 
     </shape> 
    </item> 

    <item android:state_selected="true" android:state_pressed="false"> 
     <shape> 
      <solid android:color="#ff0000"/> 
     </shape> 
    </item> 

    <item android:state_selected="true" android:state_pressed="true"> 
     <shape> 
      <solid android:color="#ffff00"/> 
     </shape> 
    </item> 
</selector> 

textcolor_selector.xml 내가 가진

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_selected="true" android:state_pressed="false" 
      android:color="#ff0000"/> 
    <item android:state_selected="true" android:state_pressed="true" 
      android:color="#0000ff"/> 
    <item android:state_selected="false" android:state_pressed="false" 
      android:color="#ffff00"/> 
    <item android:state_selected="false" android:state_pressed="true" 
      android:color="#00ff00"/> 
</selector> 

해봤 다 성공하지 못하면 - state_pressed 속성은 무시되지만 textcolor_selector에서만 무시됩니다. 이 문제를 이해하고 해결하도록 도와주세요.

답변

1

ActionBar 스타일링 설명서의 Customize the Text Color 섹션을 검토하십시오. 문제를 해결하는 데 도움이 될 수있는 변경 사항이있을 수 있습니다.

here 섹션은 Example theme 섹션 아래에 표시됩니다.이 섹션은 android:actionBarTabTextStyle의 예를 보여줍니다.

+0

답장을 보내 주셔서 감사합니다. 불행히도, 나는 당신이 게시 한 두 링크를 이미 보았고 그들은 도움이되지 못했습니다. ** Ad1. **이 메모는 탭 문형이 아닌 titletextstyle에 대한 것입니다. tabtextstyle에 대한 부모 계층 구조는 괜찮습니다. **** Ad2. **이 예는 텍스트 색상으로 선택 도구를 사용하지 않으며 특정 계층 구조를 사용하여 Android 3.0 미만의 기기를 지원합니다. 이 [link] (https://developer.android.com/training/basics/actionbar/styling.html#CustomText) 섹션의 "Android 3.0 이상에만 해당"섹션에서 계층 구조를 사용합니다. – whatever

+0

textcolor_selector 파일이'res/color /'디렉토리 내에 있는지 확인하십시오. ' @ color/textcolor_selector Bret

+0

당신이 안드로이드 문서에서 본 모든 예에서'state_pressed'는 [first used ] (http://developer.android.com/reference/android/content/res/ColorStateList.html) 다른 옵션보다 먼저 나열되어 있습니다 [여기] (http://developer.android.com/guide/topics/resources) /color-list-resource.html) textcolor_selector 파일에서'states'의 순서를 변경하려고합니다. 각각 ''에 대해'state_selected' 앞에'state_pressed'를 넣으십시오. – Bret

관련 문제