title: how to Change shape solid color at runtime inside Drawable xml
body: <p>I would like to change solid color in my drawable pragmatically.</p>
  
  <p>source:</p>
  
  <p><a href="https://stackoverflow.com/questions/20705992/changing-color-in-a-shape-inside-a-layer-list-programmatically">link</a></p>
  
  <p>@drawable/rightmenu_categories_title :</p>
  
  <p>
  </p>
  
  <pre><code>&lt;item
      android:id="@+id/drawable_main_title_details_content_an_item"
      &gt;
      &lt;shape android:shape="rectangle"&gt;
  
          &lt;solid android:color="#f4262b"/&gt;
          &lt;corners android:topLeftRadius="4dp"/&gt;
  
      &lt;/shape&gt;
  
  &lt;/item&gt;
  </code></pre>
  
  <p></p>
  
  <p>my layout :</p>
  
  <pre><code>&lt;RelativeLayout
      android:id="@+id/lay_rel_title_categories_rightmenucontents" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
  
      &gt;
  
      &lt;TextView
          android:id="@+id/txt_view_title_detalis_content_an_item" 
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:layout_width="120dp"
          android:layout_height="40dp"
          android:textSize="16sp"
          android:gravity="center"
          android:text="@string/str_title_categories_rightmenu"
          android:background="@drawable/rightmenu_categories_title"
          /&gt;
  
  &lt;/RelativeLayout&gt; 
  </code></pre>
  
  <hr>
  
  <pre><code>private void setColorOnTitleDetailContentAnItem(int which){
      View v = getActivity().findViewById(R.id.txt_view_title_detalis_content_an_item);
  
      LayerDrawable bgDrawable = (LayerDrawable)v.getBackground();
      final GradientDrawable shape = (GradientDrawable)  bgDrawable.findDrawableByLayerId(R.id.drawable_main_title_details_content_an_item);
      shape.setColor(Color.BLACK);
  }
  </code></pre>
  
  <p>but I get follow errors :</p>
  
  <pre><code>&gt; Caused by: java.lang.NullPointerException 02-01 19:10:05.326:
  &gt; E/AndroidRuntime(23755):  at
  &gt; ....ContentAnItem.setColorOnTitleDetailContentAnItem(ContentAnItem.java:241)
  &gt; 02-01 19:10:05.326: E/AndroidRuntime(23755):  at
  &gt; ....ContentAnItem.findViewsById(ContentAnItem.java:227)
  </code></pre>
  
  <p>on 241 line :</p>
  
  <pre><code>LayerDrawable bgDrawable = (LayerDrawable)v.getBackground();
  </code></pre>
  
  <p>on 227 line,my function is called .</p>
  
  <hr>
  
  <p><strong>solved :</strong></p>
  
  <p>in fragment class I must using rootView:</p>
  
  <pre><code>  View v = rootView.findViewById(R.id.txt_view_title_detalis_content_an_item);
  </code></pre>