title: Switching the background of an android app, based on a selected color form a spinner
body: <p>I would like to ask how can I change the background color of an android app /provided that I have an array of colors/ Below I apply the code that I tried to write in order to do this task: The task is to change the background color of the app, based on the currently chosen color from the dropdown list(spinner). I would be very grateful if you could give me some hints on how can I fix this issue.</p>
  <pre><code>package com.example.assignment3_yoanivanov_322321010;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.graphics.Color;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.LinearLayout;
  import android.widget.Spinner;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
      LinearLayout linearLayout;
      Spinner spinner;
      String[] items = {&quot;red&quot;,&quot;green&quot;,&quot;blue&quot;,&quot;orange&quot;,&quot;yellow&quot;,&quot;gray&quot;};
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          //textView = (TextView) findViewById(R.id.txtMsg);
          spinner = (Spinner) findViewById(R.id.spinner2);
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
          android.R.layout.simple_spinner_dropdown_item, items);
          spinner.setAdapter(adapter);
          spinner.setOnItemSelectedListener(this);
      }
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          String color  = parent.getItemAtPosition(position).toString();
          //Toast.makeText(parent.getContext(),color,Toast.LENGTH_LONG).show();
          switch(color){
              case &quot;red&quot;:
                  linearLayout.setBackgroundColor(Color.RED);
              case &quot;green&quot;:
                  linearLayout.setBackgroundColor(Color.GREEN);
              case &quot;blue&quot;:
                  linearLayout.setBackgroundColor(Color.BLUE);
              case &quot;orange&quot;:
                  linearLayout.setBackgroundColor(Color.rgb(255, 165, 0));
              case &quot;yellow&quot;:
                  linearLayout.setBackgroundColor(Color.YELLOW);
              case &quot;GRAY&quot;:
                  linearLayout.setBackgroundColor(Color.GRAY);
          }
  
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
      }
  }
  </code></pre>