我有7个具有以下风格的微调器:
<style name="customtheme" parent="@android:style/Theme.DeviceDefault">
<item name="android:background">@drawable/spin_bg</item>
<item name="android:layout_marginLeft">8dp</item>
<item name="android:layout_marginRight">8dp</item>
<item name="android:layout_marginBottom">8dp</item>
<item name="android:paddingLeft">5dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
</style>
当微调器选择的组合没有产生任何结果时,我尝试改变背景,如
for(int i=0;i<MySpinners.size();i++)
{
MySpinners.get(i).setBackgroundResource(R.drawable.spin_bg_red);
}
但为什么没有发生?
答案 0 :(得分:1)
试试这个:
Drawable drawableBgRed = getResources ().getDrawable (R.drawable.spin_bg_red);
for(int i=0;i<MySpinners.size();i++)
{
MySpinners.get(i).setBackground (drawableBgRed);
}
答案 1 :(得分:1)
'\0'
使用此:
Spinner
// to change background of the popup list
spinner.setPopupBackgroundResource(R.drawable.spinner_background);
// to change the `Spinner` background
spinner.setBackgroundResource(R.drawable.your_drawable_name);
spinner_background.xml