How to set background of an spinner dialog
Hi I want to set the background for the dialog of my spinner. I am using following code
<Spinner android:id="@+id/my_ac_debt_card_spinner"
android:layout_toRightOf="@+id/my_ac_debt_card_text" android:entries="@array/my_ac_debt_array"
android:layout_marginRight="10dip" android:layout_marginLeft="50dip"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/my_ac_spinner_bg" android:paddingLeft="5dip"
android:gravity="center_vertical" android:popupBackground="@drawable/my_ac_round_rect"/>
Java co开发者_如何学JAVAde is like this:
Spinner spin = (Spinner) findViewById(R.id.my_ac_debt_card_spinner);
final ArrayAdapter<String> a = new SpinnerAdapter(
getActivity(),
android.R.layout.simple_spinner_dropdown_item,
debit_array);
spin.setAdapter(a);
But I am not able to set background of the popup dialog. Can anyone please help me to solve this issue. Thanks in advance.
Try putting this code into your ListAdapter for the Spinner in getDropDownView:
if (parent != null && parent instanceof ListView) {
((ListView) parent).setBackgroundResource(R.drawable.background);
}
Try changing
android:popupBackground="@drawable/my_ac_round_rect" to
to
android:background="@drawable/my_ac_round_rect"
Also, here's a good blog I found on customizing a spinner: http://www.gersic.com/blog.php?id=57
精彩评论