2012-02-08 82 views
0

我以這種方式覆蓋微調器的行爲,將奇數和偶數顏色添加到下拉列表中。Android微調器行爲

SimpleCursorAdapter productsListAdapter = new SimpleCursorAdapter(MyActivity.this, R.layout.spinner_drop_down_products, cursor, column, viewIds) { 
    @Override 
    public View getDropDownView(int position, View convertView, ViewGroup parent) { 
     View view = super.getDropDownView(position, convertView, parent); 
     if (position % 2 == 0) { 
      view.setBackgroundColor(android.graphics.Color.rgb(255, 255, 255)); 
     } else { 
      view.setBackgroundColor(android.graphics.Color.rgb(214, 214, 214)); 
     } 
     return view; 
    } 
}; 

下拉列表看起來像我所期望的...但我鬆開按下每一行的亮點。 我忘了添加到代碼中? 感謝

回答

0

實際上Android框架採用像所有國家選擇:

  1. normal enabled
  2. pressed
  3. highlight
  4. focused

對列表中的默認選擇爲list_selector_background.xml你可以see here。您需要提供this by yourself。說你已經做出了you_own_selector.xml 那麼你就會把這個作爲你的視圖的這樣一個背景:

view.setBackgroundColor(R.drawable.you_own_selector); 

Here是另一個不錯的職位有關Android的使用選擇。