How do I change the textColor of all elements in the popup android counter?

I am working on an application that presents a user with two graphics. Each object is associated with a corresponding counter from which the user can select one of several attributes. Touching one counter deactivates the other (this is handled outside of spinner.setEnabled.)

The view contains a single search bar from which the user can control the range of values ​​applied to the last selected attribute.

Color is one of the attributes. When the arrow moves, I can change the background color of the floating elements. I need to set the text color of all items to black for light background colors and white for all dark colors.

    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);
    }

      

I haven't found a way to do this. Looping via spinner.getChildAt (i) only affects the currently displayed item, not those hidden in the popup.

Any suggestions would be appreciated.

+3


source to share


1 answer


This obviously does the trick:

    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);

      



It seems that the getDropDownView event is raised for every item in the dropdown.

0


source







All Articles