2011-06-15 5 views
2

내 seTabColor()에서 제목 텍스트의 색상을 회색으로 설정하고 있습니다. 누를 때 흰색으로 변경하고 싶습니다. 내가 어떻게 해?눌렀을 때 탭의 텍스트 색상을 변경하는 방법 (currentTab)?

public void setTabColor(TabHost tabHost) { 
     for(int i = 0; i<tabHost.getTabWidget().getChildCount(); i++) { 
//   tabHost.getTabWidget().getChildAt(i).setBackgroundResource(r[i]); 
      tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.BLACK); 
      TextView t = (TextView) getTabWidget().getChildAt(i).findViewById(android.R.id.title); 
      t.setTextSize(9 * getResources().getDisplayMetrics().density); 
//   tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 58; 
//   tabHost.getTabWidget().getChildAt(i).().height = 58; 
      TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); 
      tv.setTextColor(Color.GRAY); 

}

내가 좋아하는 뭔가를 할 싶어 : tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab())...

그러나 조건부 텍스트 색상을 변경하는 것을 사용하는 방법 임 확실하지.

답변

1

먼저 가능한 경우 XML로 UI를 정의하십시오.

State List Drawable Resource을 살펴보십시오. 보기를 누르고 강조 표시 할 때 사용할 이미지를 정의 할 수 있습니다. 정의한 후에는 다른 리소스와 마찬가지로 XML 파일을 사용할 수 있습니다.

예 :

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" 
      android:drawable="@drawable/button_pressed" /> <!-- pressed --> 
    <item android:state_focused="true" 
      android:drawable="@drawable/button_focused" /> <!-- focused --> 
    <item android:drawable="@drawable/button_normal" /> <!-- default --> 
</selector> 

This layout XML applies the state list drawable to a Button: 

<Button 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:background="@drawable/button" /> 
5

특히 쇼에 this answer, 시도 : 고해상도/드로어 블/사진 button.xml에 저장 XML 파일

<item name="android:textColor">@android:color/tab_indicator_text</item> 

당신은 만들어 그 기본 textColor을 재정의 할 수 있습니다 당신의 자신의 색상 선택기 (프로젝트에 res/color/ 디렉토리를 만들고 여기에 tab_indicator_text.xml이라는 새 파일을 만들고 위의 값을 자신의 색상 선택기와 일치하도록 변경하십시오 (@color/tab_indicator_text). tab_indicator_text.xml 파일의 내용은 this answer에 언급 된 것과 같은, 선택기 목록 될 것입니다 :

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_selected="true" android:color="@color/white" /> 
    <item android:state_focused="true" android:color="@color/white" /> 
    <item android:state_pressed="true" android:color="@color/white" /> 
    <item android:color="#bfbfbf" /> 
</selector> 
0

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html 그냥 거기 가서 당신은 u는 뭘 원하는지 알게 waill.

tabHost.getTabWidget(). getChildAt (0) .setBackgroundColor (Color.RED);

+0

이것은 탭의 배경 색상을 변경하기위한 것입니다. 탭의 텍스트보기 색상 만 변경하고 싶습니다. 내 탭에는 이미지와 텍스트보기가 있습니다. 탭의 텍스트보기 색상 만 변경하고 싶습니다. – Prabha1

관련 문제