title: Android Spinner created dynamically change selected item background color
body: <p>I'm creating a Spinner dynamically like the code below:</p>
  
  <pre><code>private void createCoordinationSpinner() {
      TextView tvwCoordination = new TextView(this);
      this.spinnerCoordination = new Spinner(this);
  
      //Some code to setup textview... 
  
      LinearLayout.LayoutParams paramsSpinnerCoordination = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
      paramsSpinnerCoordination.setMargins(10, 0, 10, 0);
  
      this.spinnerCoordination.setLayoutParams(paramsSpinnerCoordination);
      this.spinnerCoordination.setBackgroundResource(R.drawable.rounded_border);
      this.spinnerCoordination.setPrompt("Coordination");
      this.spinnerCoordination.setOnItemSelectedListener(spinnerItemClickListener);
  
      //Adding both views to an existing LinearLayout, that is possible to have another views, instead of spinner
      linearSchoolCoordination.addView(tvwCoordination, 0);
      linearSchoolCoordination.addView(spinnerCoordination, 1);
      linearSchoolCoordination.setGravity(Gravity.BOTTOM);
  }
  
  //Thats the line that sets the adapter:
  adapterCoordination = new ItemSpinnerAdapter(context, R.layout.coordinationspinnerlayout, arrayCoordination);
  </code></pre>
  
  <p>rounded_border.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"&gt; 
      &lt;solid android:color="@color/gray_dialog" /&gt; 
      &lt;padding android:left="8dp" 
          android:top="8dp" 
          android:right="8dp" 
          android:bottom="8dp" /&gt; 
      &lt;corners android:radius="20dp" /&gt; 
  &lt;/shape&gt;
  </code></pre>
  
  <p>coordinationspinnerlayout.xml:</p>
  
  
  
  <pre><code>&lt;LinearLayout   android:orientation="vertical" 
                  android:background="@color/transparent2" 
                  android:layout_height="fill_parent" 
                  android:layout_width="fill_parent" 
                  xmlns:android="http://schemas.android.com/apk/res/android"&gt; 
  
      &lt;LinearLayout
          android:id="@+id/linearLayout2"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="@color/transparent2"
          android:orientation="vertical" &gt;
  
          &lt;LinearLayout
              android:id="@+id/linearLayout1"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:background="@color/transparent2"
              android:gravity="center_vertical" &gt;
  
              &lt;ImageView  android:layout_height="wrap_content" 
                          android:layout_width="wrap_content" 
                          android:id="@+id/imageSpinnerItem" 
                          android:src="@drawable/itemlistviewicon_nochildren" 
                          android:layout_marginTop="5dp" 
                          android:layout_marginLeft="8dp" 
                          android:layout_marginBottom="5dp"/&gt; 
  
              &lt;TextView   android:layout_height="wrap_content" 
                          android:layout_width="wrap_content" 
                          android:id="@+id/tvwSpinnerCoordination" 
                          android:layout_marginLeft="10dp" 
                          android:textSize="16dip" 
                          android:textColor="@color/black" 
                          android:text="TextView" 
                          android:layout_weight="1"/&gt; 
  
              &lt;ImageView  android:layout_height="20dp" 
                          android:layout_width="20dp" 
                          android:id="@+id/imageSpinnerDownArrow" 
                          android:src="@drawable/spinnerdownarrow" 
                          android:layout_marginTop="5dp" 
                          android:layout_marginBottom="5dp" 
                          android:layout_marginRight="10dp"/&gt; 
          &lt;/LinearLayout&gt; 
  
          &lt;View   android:background="@color/silver" 
                  android:layout_height="1dp" 
                  android:layout_width="fill_parent" 
                  android:id="@+id/linearSpinnerSeparator"/&gt; 
  
      &lt;/LinearLayout&gt; 
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And finally, the adapter, ItemSpinnerAdapter.java:</p>
  
  <pre><code>public class ItemSpinnerAdapter extends ArrayAdapter&lt;CoordinationData&gt; 
  {
      private int tvwID;
      private List&lt;CoordinationData&gt; coordinationList;
  
      public ItemSpinnerAdapter(Context context, int textViewResourceId, List&lt;CoordinationData&gt; coordinationList) 
      {
          super(context, textViewResourceId, coordinationList);
  
          this.tvwID = textViewResourceId;
          this.coordinationList = coordinationList;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) 
      {
          ViewHolder holder;
          View view = convertView;
  
          if (view == null) 
          {
             LayoutInflater layInf = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             view = layInf.inflate(tvwID, null);
  
             holder = new ViewHolder();
             holder.tvwDescription = (TextView) view.findViewById(R.id.tvwSpinnerCoordination);
             holder.description = coordinationList.get(position).getCoordinationName();
  
             view.findViewById(R.id.linearSpinnerSeparator).setVisibility(View.GONE);
             view.setTag(holder);
  
          } 
          else 
          {
              holder = (ViewHolder) view.getTag();
              holder.description = coordinationList.get(position).getCoordinationName();
          }
  
          if (holder.tvwDescription != null) 
              holder.tvwDescription.setText(holder.description);
  
          return view;
      }
  
      @Override
      public View getDropDownView(int position, View convertView, ViewGroup parent) 
      {
          ViewHolder holder;
          View view = convertView;
  
          if (view == null) 
          {
              LayoutInflater layInf = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              view = layInf.inflate(tvwID, null);
  
              holder = new ViewHolder();
              holder.tvwDescription = (TextView) view.findViewById(R.id.tvwSpinnerCoordination);
              holder.tvwDescription.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
              holder.description = coordinationList.get(position).getCoordinationName();
  
              view.findViewById(R.id.imageSpinnerDownArrow).setVisibility(View.GONE);
              view.setTag(holder);
  
          } 
          else 
          {
              holder = (ViewHolder) view.getTag();
              holder.description = coordinationList.get(position).getCoordinationName();
          }
  
          if (holder.tvwDescription != null) 
              holder.tvwDescription.setText(holder.description);
  
      return view;
  }
  
  public class ViewHolder 
  {
      TextView tvwDescription;
      String description;
  }
  }
  </code></pre>
  
  <p>adding it to a LinearLayout that already exists in my activity's XML layout file.
  Along with my CustomSpinnerAdapter, it works pretty well.
  But I still need to change some properties and I'm stucked...
  Since my app is using blue texts and backgrounds, I'd like to set the selection of a spinner item highlight color. Its default is orange.</p>
  
  <p>Since I'm developing for API 10, I'm using limited Spinner methods.</p>
  
  <p>Any suggestions?
  Thanks in advance!</p>
  
  <p>EDIT: is that possible to change prompt header background color?</p>
  
  <p>EDIT2: adding further code.</p>