title: Generate and set random colors on text view background within Recycler View in Android
body: <p>I am Trying to Generate Random Colors and set the Random color as background of Text View Just Like in GMail app. The Text view is Having a circular background initially set in xml which i have done using shape. I have done some research and used some code available on internet but the changes are not reflecting in my app. 
  <a href="https://i.stack.imgur.com/UFS5K.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/UFS5K.jpg" alt="Gmail"></a></p>
  
  <p>Below is my Recycler View Adapter Class: </p>
  
  <pre><code>    public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.Items&gt; {
          ArrayList&lt;GmailDataHolder&gt; data;
          Context context;
  
          public RecyclerViewAdapter(ArrayList&lt;GmailDataHolder&gt; data, Context context) {
              this.data = data;
              this.context = context;
          }
  
          @Override
          public RecyclerViewAdapter.Items onCreateViewHolder(ViewGroup parent, int viewType) {
              View v = LayoutInflater.from(context).inflate(R.layout.gmail_layout_row, parent, false);
              Items i = new Items(v);
              return i;
  
  
          }
  
          @Override
          public void onBindViewHolder(final RecyclerViewAdapter.Items holder, int position) {
  
  //Generating Random Color
              int randomAndroidColor = holder.androidColors[new Random().nextInt(holder.androidColors.length)];
              Drawable background = holder.circleTv.getBackground();
              if (background instanceof ShapeDrawable) {
                  ((ShapeDrawable)background).getPaint().setColor(randomAndroidColor);
              } else if (background instanceof GradientDrawable) {
                  ((GradientDrawable)background).setColor(randomAndroidColor);
              } else if (background instanceof ColorDrawable) {
                  ((ColorDrawable)background).setColor(randomAndroidColor);
              }
              holder.line1.setText(data.get(position).getLine1());
              holder.line2.setText(data.get(position).getLine2() + "...");
              holder.line3.setText(data.get(position).getLine3() + "...");
              holder.time.setText(data.get(position).getTime());
  
  
              //get Star Image State from MySql DB
  
              MyFunctions.getStarState(data, holder, position);
      holder.circleTv.setText(String.valueOf(data.get(position).getLine1().charAt(0)).toUpperCase());
  
              //Changing Star Image on Click
              MyFunctions.starClickListener(holder);
  
  
          }
  
          @Override
          public int getItemCount() {
              return data.size();
          }
  
          public class Items extends RecyclerView.ViewHolder {
              TextView circleTv, line1, line2, line3, time;
              int[] androidColors;
              public ImageView star;
  
              public Items(View itemView) {
                  super(itemView);
  //Loading Color from resources
                  androidColors = itemView.getResources().getIntArray(R.array.androidcolors);
                  circleTv = (TextView) itemView.findViewById(R.id.tv_circle);
                  line1 = (TextView) itemView.findViewById(R.id.tv_line1);
                  line2 = (TextView) itemView.findViewById(R.id.tv_line2);
                  line3 = (TextView) itemView.findViewById(R.id.tv_line3);
                  time = (TextView) itemView.findViewById(R.id.tv_time);
                  star = (ImageView) itemView.findViewById(R.id.img_star);
  
  
              }
          }
  </code></pre>
  
  <p>Colors.xml File:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;color name="colorPrimary"&gt;#3F51B5&lt;/color&gt;
      &lt;color name="colorPrimaryDark"&gt;#303F9F&lt;/color&gt;
      &lt;color name="colorAccent"&gt;#dc4538&lt;/color&gt;
      &lt;color name="colorFacebook"&gt;#374dae&lt;/color&gt;
      &lt;color name="colorCenterFb"&gt;#d5617ae6&lt;/color&gt;
      &lt;color name="colorStartGoogle"&gt;#d8dd4c3a&lt;/color&gt;
      &lt;color name="colorEndGoogle"&gt;#dd4c3a&lt;/color&gt;
      &lt;color name="colorEndLinkedIn"&gt;#1887b0&lt;/color&gt;
      &lt;color name="colorStartLinkedIn"&gt;#e31887b0&lt;/color&gt;
      &lt;color name="colorStrokeLinkedIn"&gt;#ec106584&lt;/color&gt;
      &lt;color name="colorStrokeGoogle"&gt;#b73e2e&lt;/color&gt;
      &lt;color name="colorStrokeFacebook"&gt;#e2263a91&lt;/color&gt;
      &lt;color name="status"&gt;#ba3223&lt;/color&gt;
      &lt;item name="blue" type="color"&gt;#FF33B5E5&lt;/item&gt;
      &lt;item name="purple" type="color"&gt;#FFAA66CC&lt;/item&gt;
      &lt;item name="green" type="color"&gt;#FF99CC00&lt;/item&gt;
      &lt;item name="orange" type="color"&gt;#FFFFBB33&lt;/item&gt;
      &lt;item name="red" type="color"&gt;#FFFF4444&lt;/item&gt;
      &lt;item name="darkblue" type="color"&gt;#FF0099CC&lt;/item&gt;
      &lt;item name="darkpurple" type="color"&gt;#FF9933CC&lt;/item&gt;
      &lt;item name="darkgreen" type="color"&gt;#FF669900&lt;/item&gt;
      &lt;item name="darkorange" type="color"&gt;#FFFF8800&lt;/item&gt;
      &lt;item name="darkred" type="color"&gt;#FFCC0000&lt;/item&gt;
  
      &lt;integer-array name="androidcolors"&gt;
          &lt;item&gt;@color/blue&lt;/item&gt;
          &lt;item&gt;@color/purple&lt;/item&gt;
          &lt;item&gt;@color/green&lt;/item&gt;
          &lt;item&gt;@color/orange&lt;/item&gt;
          &lt;item&gt;@color/red&lt;/item&gt;
          &lt;item&gt;@color/darkblue&lt;/item&gt;
          &lt;item&gt;@color/darkpurple&lt;/item&gt;
          &lt;item&gt;@color/darkgreen&lt;/item&gt;
          &lt;item&gt;@color/darkorange&lt;/item&gt;
          &lt;item&gt;@color/darkred&lt;/item&gt;
      &lt;/integer-array&gt;
  
  
  &lt;/resources&gt;
  </code></pre>
  
  <p>Initially The TextView is having the following Background declared in xml:</p>
  
  <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="oval"&gt;
      &lt;solid
          android:color="#48b3ff"/&gt;
  &lt;/shape&gt;
  </code></pre>