title: How to set the background color of a selected item in a ToolBar Spinner. Not the normal spinner
body: <p>I need to change the Background color of a <strong>toolbar spinner</strong>. I can't do it the normal way because It is not the normal type of Spinner you just drag and drop into your layout. I didn't write this code. I am editing it but it is giving me a tough time.</p>
  
  <p>This is the code of it in the main layout. This method gets called amongst multiple fragments:</p>
  
  <pre><code>@Override
  public void setToolbarSpinner(BarComponentAttributes bca) {
      int grey3 = ContextCompat.getColor(this, R.color.grey3);
      toolbar.setBackgroundColor(grey3);
      RelativeLayout rl = toolbar.findViewById(R.id.mainToolbarActionButtonsContainer);
      clearViewsInRl(rl);
      rl.setBackgroundColor(grey3);
      FragmentBarUtil.customSpinnerViewForBar(bca, rl);
  }
  </code></pre>
  
  <p>I found this solution below on stack overflow and implemented it in a test project, but I have no way to implement it in the method above:</p>
  
  <pre><code>        ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, list) {
  
          @Override
          public View getDropDownView(int position, View convertView, ViewGroup parent)
          {
              View v = null;
              v = super.getDropDownView(position, null, parent);
              // If this is the selected item position
              if (position == selectedItem[0]) {
                  v.setBackgroundColor(Color.BLUE);
              }
              else {
                  // for other views
                  v.setBackgroundColor(Color.WHITE);
  
              }
              return v;
          }
      };
  
      dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinner.setAdapter(dataAdapter);
  
      spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              selectedItem[0] = position;
              Toast.makeText(MainActivity.this, ""+parent.getItemAtPosition(position), Toast.LENGTH_SHORT).show();
  
         }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
      });
  </code></pre>