我加入了一個自定義listadapter一個微調使用這種佈局:如何更改微調框的顏色而不是下拉菜單項?
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center"
android:textColor="@drawable/default_spinner_item_text"
android:text="Sample Text"
android:textSize="20dp"
android:paddingBottom="7.5dp"
android:background="@drawable/default_spinner_item"
android:paddingTop="7.5dp">
</TextView>
繪製對象default_spinner_item:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/default_button_text_color" />
<item android:state_checked="true" android:drawable="@android:color/transparent"/>
<item android:state_single="true" android:drawable="@android:color/transparent"/>
<item android:state_active="true" android:drawable="@android:color/transparent"/>
<item android:state_first="true" android:drawable="@android:color/transparent"/>
<item android:state_focused="true" android:drawable="@android:color/transparent" />
<item android:state_selected="true" android:drawable="@android:color/transparent" />
<item android:drawable="@color/default_button_border_color" />
</selector>
的微調八方通得到的顏色與下拉項目一樣...
我已經嘗試了所有的狀態,但它不可能使旋轉器項目背景變爲透明,而下拉列表變爲彩色(default_button_border_color)。
@Solved
這是我的適配器:
public class CustomSpinnerAdapter extends ArrayAdapter<String> {
private int _resource;
private Typeface _typeFace;
public CustomSpinnerAdapter(MainActivity context, int resource, List<String> items) {
super(context, resource, items);
_resource = resource;
_typeFace = context.getDefaultAppTypeFace();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView view = (TextView)super.getView(position, convertView, parent);
if(convertView == null)
view.setTypeface(_typeFace);
}
return view;
}
@Override
public TextView getDropDownView(int position, View convertView, ViewGroup parent) {
TextView view = (TextView) super.getDropDownView(position, convertView, parent);
if(convertView == null)
view.setTypeface(_typeFace);
}
return view;
}
}
我現在用兩個佈局,一個用於視圖和一個用於dropdownview。我的代碼中的另一個錯誤是我調用了super.getView(position,convertView,parent);在getDropDownView ovverride中。