2011-10-14 43 views

回答

3

在您使用的適配器中,您應該覆蓋getGroupView()方法。其中一個參數是isExpanded布爾值。只需使用該值來決定設置問題textview的顏色。下面是一個例子:

@Override 
public void getGroupView(int groupPosition, boolean isExpanded, 
     View convertView, ViewGroup parent) { 
    // Here you would do your convertView initialization 
    // ... 
    TextView textView = (TextView) convertView.findViewById(R.id.textview); 
    if(isExpanded) 
     textView.setTextColor(/* some color */); 
    else 
     textView.setTextColor(/* some other color */); 
    // Do the rest of your view binding 
    //... 
} 
+0

我知道textView.setTextColor(/ *一些其它顏色* /);是解決方案,但這並不適合我。我不明白爲什麼它不起作用。 – Sachchidanand

+0

如果您發佈您的代碼,它會更容易幫助。 – jvergeldedios

0

這裏是代碼:

@Override 
     public View getGroupView(int groupPosition, boolean isExpanded, 
       View convertView, ViewGroup parent) { 
      View parentView = (View)convertView.findViewById(R.id.settings_menu); 
      parentView.setBackgroundResource(R.drawable.background1); 

      TextView parentTextView = (TextView)convertView.findViewById(R.id.menu_title); 
      parentTextView.setText(groups[ groupPosition ].toString()); 

      if(isExpanded){ 
       convertView.setBackgroundResource(R.drawable.settings_background2); 
       parentTextView.setTextColor(R.color.black); 
      } 

      return convertView ; 
     }