我正在开发一个应用程序,为用户呈现两个图形对象。每个对象都与相应的微调器相关联,用户可以从中选择少数属性之一。触摸一个微调器将停用另一个(这是在spinner.setenabled之外处理的)。
该视图包含一个seekbar,用户可以从中控制应用于最近选定属性的值的范围。
颜色是属性之一。当seekbar移动时,我可以更改弹出项的背景色。我需要将所有项目的文本颜色设置为黑色(对于浅背景色)和白色(对于所有深色)。

    if ( pos == object.COLOR_INDEX) {
             //change spinner Background and Text color
             spinner.setBackgroundColor(Colors.BACKGROUND[objectCurrent.getParams(pos)]);
             TextView v ; int ct ;
             for(int i=0; i<(ct=spinner.getChildCount()); ++i) {
                 v= (TextView)spinner.getChildAt(i);
                 v.setTextColor(Colors.FOREGROUND[objectCurrent.getParams(pos)]);
             }



             ColorDrawable drawable=(ColorDrawable) spinner.getBackground() ;
             spinner.setPopupBackgroundDrawable(drawable);
             spinner.setSelection(0); spinner.setSelection(pos);
    }

我还没找到办法。在微调器中循环。getchildat(i)只影响当前显示的项,而不影响弹出窗口中隐藏的项。
如有任何建议,我将不胜感激。

最佳答案

这显然起到了作用:

    Resources res=getResources();
    final List<String> spinnerItems=new ArrayList<String>(Arrays.asList(res.getStringArray(R.array.spin_settings)));

    ArrayAdapter<String> aa=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,spinnerItems){
        public View getDropDownView(int position, View convertView,
                                    ViewGroup parent) {
            View v = super.getDropDownView(position, convertView,
                    parent);

            ((TextView) v).setTextColor(Colors.FOREGROUND[obj.getParams(param.COLOR_INDEX)]);
            ((TextView) v).setBackgroundColor(Colors.BACKGROUND[obj.getParams(param.COLOR_INDEX)]);


            return v;
        }

    };

     aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);



    spinnerLeft.setAdapter(aa);
    spinnerRight.setAdapter(aa);

对于下拉列表中的每个项,getDropDownView事件似乎都会被引发。

10-07 19:19
查看更多