我在运行时创建自定义微调器。运行应用程序后,微调器样式已成功更改,但单击微调器时不再有下拉列表。任何帮助将不胜感激。
styles.xml
中的代码<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="@attr/spinner_style">@style/spinner_style</item>
</style>
<style name="spinner_style" parent="@android:style/Theme.Holo.Light">
<item name="android:background">@drawable/gradiant_spinner</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:layout_marginRight">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:popupBackground">#DFFFFFFF</item>
</style>
attr.xml 中的
<?xml version="1.0" encoding="utf-8"?>
<resources> <attr name="spinner_style" format="reference"/></resources>
MyCustomSpinner :中的
public class MyCustomSpinner extends Spinner
{
public MyCustomSpinner(Context context) {
super(context, null, R.attr.spinner_style);
}
}
活动:中的
final MyCustomSpinner spinner = new MyCustomSpinner(context); //INITIALIZE THE SPINNER
spinner.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, lookupValues));
答案 0 :(得分:0)
试试这个:
final MyCustomSpinner spinner = new MyCustomSpinner(context);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter, lookupValues));
adapter.notifyDataSetChanged();
如果不起作用,请尝试MyCustomSpinner spinner = ..