2012-01-02 64 views
1

下面是我的適配器的代碼,它允許創建一個彈出窗口,其中包含我的listview中每個項目的第一個字母,並提供與聯繫人應用程序相似的內容。如何更改SectionIndexer中彈出的顏色?

enter image description here

不幸的是,顏色是不正確和文本是黑灰色的背景。我的問題是:

我在哪裏可以更改這些顏色?

public class AlphabeticalAdapter extends ArrayAdapter<String> implements 
     SectionIndexer { 

    HashMap<String, Integer> alphaIndexer; 
    String[] sections; 

    public AlphabeticalAdapter(Context context, String[] items) { 
     super(context, android.R.layout.simple_list_item_1, items); 

     alphaIndexer = new HashMap<String, Integer>(); 
     int size = items.length; 

     for (int x = 0; x < size; x++) { 
      String s = items[x]; 

      // get the first letter of the store 
      String ch = s.substring(0, 1); 
      // convert to uppercase otherwise lowercase a -z will be sorted 
      // after upper A-Z 
      ch = ch.toUpperCase(); 

      // HashMap will prevent duplicates 
      alphaIndexer.put(ch, x); 
     } 

     Set<String> sectionLetters = alphaIndexer.keySet(); 

     // create a list from the set to sort 
     ArrayList<String> sectionList = new ArrayList<String>(sectionLetters); 

     Collections.sort(sectionList); 

     sections = new String[sectionList.size()]; 

     sectionList.toArray(sections); 
    } 

    public int getPositionForSection(int section) { 
     return alphaIndexer.get(sections[section]); 
    } 

    public int getSectionForPosition(int position) { 
     return 1; 
    } 

    public Object[] getSections() { 
     return sections; 
    } 
} 
+1

從它的外觀我不認爲你可以做到這一點。但是[可選](http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List9.html),您可以相應地自定義窗口,但也請注意按部分截斷。 – st0le 2012-01-02 10:05:01

+0

這是答案,你可以發佈它,並會接受;-) – 2012-01-02 10:42:02

+0

完成! :)填充 – st0le 2012-01-02 11:49:36

回答

1

從它的外觀我不認爲你可以做到這一點。但這裏有一個alternative你可以相應地自定義窗口,但也注意到這不會按照部分快照。