Change color of shape dynamically
<p>Before marking this as a duplicate, please read my question first.</p>

<p>I have a shape with the id "rectangle" which looks like this:</p>

<pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rectangle"&gt;
    &lt;padding android:left="2dp"
        android:top="2dp"
        android:right="2dp"
        android:bottom="2dp" /&gt;
    &lt;corners android:radius="3dp" /&gt;
    &lt;solid android:color="#ff5900" /&gt;
&lt;/shape&gt;
</code></pre>

<p>I use this shape in a <code>cardview</code> of mine:</p>

<pre><code>&lt;View
    android:id="@+id/myrectangle"
    android:layout_width="15dp"
    android:layout_height="wrap_content"
    android:background="@drawable/rectangle"
    android:layout_alignBottom="@+id/desc" /&gt;
</code></pre>

<p>And finally, I try to set the color in the <code>RVAdapter</code> of the <code>cardview</code>:
(Color is a <code>View</code> and gd is a <code>Drawable</code>)</p>

<pre><code>color = cv.findViewById(R.id.myrectangle);
gd = color.getBackground();
if (omission.gd instanceof ShapeDrawable) {
    ((ShapeDrawable)omission.gd).getPaint().setColor(Color.parseColor(stundenplandata.getJSONObject(i).getString("color")));
} else if (omission.gd instanceof GradientDrawable) {
    ((GradientDrawable)omission.gd).setColor(Color.parseColor(stundenplandata.getJSONObject(i).getString("color")));
} else if (omission.gd instanceof ColorDrawable) {
    ((ColorDrawable)omission.gd).setColor(Color.parseColor(stundenplandata.getJSONObject(i).getString("color")));
}
</code></pre>

<p>The <code>stundenplandata.getjsonobject</code> etc is just getting the hex code for the color.</p>

<p>However, when I do this, the color of the rectangle is not changing, it actually changes to white (remember, it is orange in the xml file).</p>

<p>What is my problem/mistake?</p>

<p>EDIT: Here's the view hierarchy:</p>

<pre><code>com.android.internal.policy.PhoneWindow$DecorView{a4dd2b7 V.E..... ... 0,0-1080,1920}
    android.widget.LinearLayout{9e0aa24 V.E..... ... 0,0-1080,1920}
      android.view.ViewStub{457998d G.E..... ... 0,0-0,0 #10203be android:id/action_mode_bar_stub}
      android.widget.FrameLayout{a238742 V.E..... ... 0,0-1080,1920}
        android.support.v7.widget.FitWindowsLinearLayout{362e353 V.E..... ... 0,0-1080,1920 #7f0f007b app:id/action_bar_root}
          android.support.v7.widget.ViewStubCompat{7904490 G.E..... ... 0,0-0,0 #7f0f007c app:id/action_mode_bar_stub}
          android.support.v7.widget.ContentFrameLayout{4b14189 V.E..... ... 0,0-1080,1920 #1020002 android:id/content}
            android.support.v4.widget.DrawerLayout{a66d58e VFED.... ... 0,0-1080,1920 #7f0f00b2 app:id/material_drawer_layout}
              android.support.v4.widget.DrawerLayout{cae61af VFED.... ... 0,0-1080,1920 #7f0f00b2 app:id/material_drawer_layout}
                android.support.design.widget.CoordinatorLayout{45d19bc V.ED.... ... 0,0-1080,1920}
                  android.support.design.widget.AppBarLayout{55ce6b8 V.E..... ... 0,72-1080,240}
                    android.support.v7.widget.Toolbar{ce36d45 V.E..... ... 0,0-1080,168 #7f0f0094 app:id/toolbar}
                      android.support.v7.widget.AppCompatTextView{7ebc9a V.ED.... ... 48,43-383,124}
                      android.support.v7.widget.ActionMenuView{c8969cb V.E..... ... 960,0-1080,168}
                        android.support.v7.widget.ActionMenuPresenter$OverflowMenuButton{2c015a8 VFED..C. ... 0,12-120,156}
                  android.widget.RelativeLayout{12a7c91 V.E..... ... 0,240-1080,1920}
                    android.widget.FrameLayout{a5298c1 V.E..... ... 30,0-1050,1680 #7f0f0099 app:id/main_container_1}
                      android.widget.FrameLayout{5fc0866 V.E..... ... 0,0-1020,1680}
                        com.dnddev.sos.MyRecyclerView{bc2d7a7 VFED.... F.. 0,0-1020,1680 #7f0f00aa app:id/rv_lessons}
                          android.widget.LinearLayout{1d4e454 V.E..... ... 0,0-1020,491}
                            android.support.v7.widget.CardView{22efffd V.E..... ... 15,15-1005,476 #7f0f0095 app:id/lessonscard}
                              android.widget.RelativeLayout{ab044f2 V.E..... ... 0,0-990,461}
                                android.view.View{73b4743 V.ED.... ... 0,461-45,461 #7f0f00ad app:id/myrectangle}
                                android.support.v7.widget.AppCompatTextView{4c5f1c0 V.ED.... ... 45,54-615,310 #7f0f00af app:id/headline}
                                android.support.v7.widget.AppCompatTextView{2709ef9 V.ED.... ... 45,310-251,461 #7f0f00ae app:id/desc}
                                android.support.v7.widget.AppCompatTextView{7f9be3e V.ED.... ... 45,54-212,127 #7f0f00b0 app:id/initials}
                                android.support.v7.widget.AppCompatTextView{f41149f V.ED.... ... 737,54-990,127 #7f0f00b1 app:id/time}
                          android.widget.LinearLayout{4f869ec V.E..... ... 0,491-1020,982}
                            android.support.v7.widget.CardView{69331b5 V.E..... ... 15,15-1005,476 #7f0f0095 app:id/lessonscard}
                              android.widget.RelativeLayout{ccf804a V.E..... ... 0,0-990,461}
                                android.view.View{ac5bbb V.ED.... ... 0,461-45,461 #7f0f00ad app:id/myrectangle}
                                android.support.v7.widget.AppCompatTextView{af838d8 V.ED.... ... 45,54-484,310 #7f0f00af app:id/headline}
                                android.support.v7.widget.AppCompatTextView{c123431 V.ED.... ... 45,310-251,461 #7f0f00ae app:id/desc}
                                android.support.v7.widget.AppCompatTextView{e8d5716 V.ED.... ... 45,54-206,127 #7f0f00b0 app:id/initials}
                                android.support.v7.widget.AppCompatTextView{3baf897 V.ED.... ... 737,54-990,127 #7f0f00b1 app:id/time}
                          android.widget.LinearLayout{a240a84 V.E..... ... 0,982-1020,1473}
                            android.support.v7.widget.CardView{2a4e26d V.E..... ... 15,15-1005,476 #7f0f0095 app:id/lessonscard}
                              android.widget.RelativeLayout{a7fcea2 V.E..... ... 0,0-990,461}
                                android.view.View{cac8733 V.ED.... ... 0,461-45,461 #7f0f00ad app:id/myrectangle}
                                android.support.v7.widget.AppCompatTextView{b194af0 V.ED.... ... 45,54-517,310 #7f0f00af app:id/headline}
                                android.support.v7.widget.AppCompatTextView{43a3869 V.ED.... ... 45,310-251,461 #7f0f00ae app:id/desc}
                                android.support.v7.widget.AppCompatTextView{43032ee V.ED.... ... 45,54-212,127 #7f0f00b0 app:id/initials}
                                android.support.v7.widget.AppCompatTextView{a1e638f V.ED.... ... 737,54-990,127 #7f0f00b1 app:id/time}
                        com.melnykov.fab.FloatingActionButton{e0261c VFED..C. ... 804,1464-972,1632 #7f0f00ab app:id/lessons_fab}
                com.mikepenz.materialize.view.ScrimInsetsRelativeLayout{b4f225 I.ED.... ... -912,0-0,1920 #7f0f0018 app:id/material_drawer_slider_layout}
                  android.view.View{c708ffa G.ED.... ... 0,0-0,0 #7f0f00ca app:id/material_drawer_inner_shadow}
                  android.support.v7.widget.RecyclerView{d27a9ab VFED.V.. ... 0,0-912,1920 #7f0f00c9 app:id/material_drawer_recycler_view}
              com.mikepenz.materialize.view.ScrimInsetsRelativeLayout{4d78808 I.ED.... ... -912,0-0,1920 #7f0f0018 app:id/material_drawer_slider_layout}
                android.view.View{9678ba1 G.ED.... ... 0,0-0,0 #7f0f00ca app:id/material_drawer_inner_shadow}
                android.support.v7.widget.RecyclerView{d27b1c6 VFED.V.. ... 0,0-912,1920 #7f0f00c9 app:id/material_drawer_recycler_view}
                  android.widget.LinearLayout{7353587 V.....CL ... 0,0-912,543 #9e626c54}
                    android.widget.FrameLayout{5611cb4 V.E...C. ... 0,0-912,516}
                      android.support.v7.widget.AppCompatImageView{85040dd V.ED.... ... 0,0-912,516 #7f0f00b3 app:id/material_drawer_account_header_background}
                      android.widget.RelativeLayout{5dd2452 V.E..... ... 0,0-912,516 #7f0f00b4 app:id/material_drawer_account_header}
                        com.mikepenz.materialdrawer.view.BezelImageView{9a5a323 V.ED..CL ... 48,120-240,312 #7f0f00b8 app:id/material_drawer_account_header_current}
                        android.widget.LinearLayout{34d5020 V.E..... ... 912,120-912,120}
                          com.mikepenz.materialdrawer.view.BezelImageView{f150dd9 G.ED..C. ... 0,0-0,0 #7f0f00b5 app:id/material_drawer_account_header_small_first}
                          com.mikepenz.materialdrawer.view.BezelImageView{505339e G.ED..C. ... 0,0-0,0 #7f0f00b6 app:id/material_drawer_account_header_small_second}
                          com.mikepenz.materialdrawer.view.BezelImageView{3254e7f G.ED..C. ... 0,0-0,0 #7f0f00b7 app:id/material_drawer_account_header_small_third}
                        android.widget.LinearLayout{a074e4c V.E..... ... 0,324-912,492 #7f0f00b9 app:id/material_drawer_account_header_text_section}
                          android.support.v7.widget.AppCompatTextView{9bfae95 V.ED.... ... 48,27-744,84 #7f0f00ba app:id/material_drawer_account_header_name}
                          android.support.v7.widget.AppCompatTextView{a0cebaa V.ED.... ... 48,84-744,141 #7f0f00bb app:id/material_drawer_account_header_email}
                        android.support.v7.widget.AppCompatImageView{6ca539b V.ED.... ... 798,408-864,474 #7f0f00bc app:id/material_drawer_account_header_text_switcher}
                    android.view.View{e810338 V.ED.... ... 0,516-912,519}
                  android.widget.LinearLayout{d09d768 V.E...CL ... 0,543-912,687 #1}
                    android.support.v7.widget.AppCompatImageView{1399f11 V.ED.... ... 48,0-216,144 #7f0f00be app:id/material_drawer_icon}
                    android.widget.LinearLayout{c261876 V.E..... ... 216,0-864,144}
                      android.support.v7.widget.AppCompatTextView{8f08e77 V.ED.... ... 0,43-648,100 #7f0f00bf app:id/material_drawer_name}
                      android.support.v7.widget.AppCompatTextView{df1ae4 G.ED.... ... 0,0-0,0 #7f0f00c0 app:id/material_drawer_description}
                    android.widget.LinearLayout{9881b4d G.E..... ... 0,0-0,0 #7f0f00c4 app:id/material_drawer_badge_container}
                      android.support.v7.widget.AppCompatTextView{1d34602 G.ED.... ... 0,0-0,0 #7f0f00c3 app:id/material_drawer_badge}
                  android.widget.RelativeLayout{dd59b13 V......L ... 0,687-912,738 #9e626c52}
                    android.view.View{ce50150 V.ED.... ... 0,24-912,27 #7f0f00bd app:id/material_drawer_divider}
                  android.widget.LinearLayout{7c81f49 V.E...CL .S. 0,738-912,882 #2}
                    android.support.v7.widget.AppCompatImageView{533c04e V.ED.... .S. 48,0-216,144 #7f0f00be app:id/material_drawer_icon}
                    android.widget.LinearLayout{5f4d56f V.E..... .S. 216,0-864,144}
                      android.support.v7.widget.AppCompatTextView{520e27c V.ED.... .S. 0,43-648,100 #7f0f00bf app:id/material_drawer_name}
                      android.support.v7.widget.AppCompatTextView{bea6705 G.ED.... .S. 0,0-0,0 #7f0f00c0 app:id/material_drawer_description}
                    android.widget.LinearLayout{10f935a G.E..... .S. 0,0-0,0 #7f0f00c4 app:id/material_drawer_badge_container}
                      android.support.v7.widget.AppCompatTextView{423598b G.ED.... .S. 0,0-0,0 #7f0f00c3 app:id/material_drawer_badge}
                  android.widget.LinearLayout{4d7aa68 V.E...CL ... 0,882-912,1026 #3}
                    android.support.v7.widget.AppCompatImageView{a2f6e81 V.ED.... ... 48,0-216,144 #7f0f00be app:id/material_drawer_icon}
                    android.widget.LinearLayout{2a38b26 V.E..... ... 216,0-864,144}
                      android.support.v7.widget.AppCompatTextView{96c0367 V.ED.... ... 0,43-648,100 #7f0f00bf app:id/material_drawer_name}
                      android.support.v7.widget.AppCompatTextView{4b10514 G.ED.... ... 0,0-0,0 #7f0f00c0 app:id/material_drawer_description}
                    android.widget.LinearLayout{6371bd G.E..... ... 0,0-0,0 #7f0f00c4 app:id/material_drawer_badge_container}
                      android.support.v7.widget.AppCompatTextView{c2d33b2 G.ED.... ... 0,0-0,0 #7f0f00c3 app:id/material_drawer_badge}
                  android.widget.LinearLayout{2ab6f03 V.E...CL ... 0,1026-912,1170 #5}
                    android.support.v7.widget.AppCompatImageView{e235e80 V.ED.... ... 48,0-216,144 #7f0f00be app:id/material_drawer_icon}
                    android.widget.LinearLayout{2da6cb9 V.E..... ... 216,0-864,144}
                      android.support.v7.widget.AppCompatTextView{436d8fe V.ED.... ... 0,43-648,100 #7f0f00bf app:id/material_drawer_name}
                      android.support.v7.widget.AppCompatTextView{3ebf85f G.ED.... ... 0,0-0,0 #7f0f00c0 app:id/material_drawer_description}
                    android.widget.LinearLayout{99fe2ac G.E..... ... 0,0-0,0 #7f0f00c4 app:id/material_drawer_badge_container}
                      android.support.v7.widget.AppCompatTextView{d2c1b75 G.ED.... ... 0,0-0,0 #7f0f00c3 app:id/material_drawer_badge}
                  android.widget.RelativeLayout{da3870a V......L ... 0,1170-912,1221 #9e626c53}
                    android.view.View{d81bb7b V.ED.... ... 0,24-912,27 #7f0f00bd app:id/material_drawer_divider}
                  android.widget.LinearLayout{37e7d98 V.E...CL ... 0,1221-912,1365 #4}
                    android.support.v7.widget.AppCompatImageView{2aff9f1 V.ED.... ... 48,0-216,144 #7f0f00be app:id/material_drawer_icon}
                    android.widget.LinearLayout{47b09d6 V.E..... ... 216,0-864,144}
                      android.support.v7.widget.AppCompatTextView{6e69457 V.ED.... ... 0,43-648,100 #7f0f00bf app:id/material_drawer_name}
                      android.support.v7.widget.AppCompatTextView{3a9db44 G.ED.... ... 0,0-0,0 #7f0f00c0 app:id/material_drawer_description}
                    android.widget.LinearLayout{ab9442d G.E..... ... 0,0-0,0 #7f0f00c4 app:id/material_drawer_badge_container}
                      android.support.v7.widget.AppCompatTextView{b75ed62 G.ED.... ... 0,0-0,0 #7f0f00c3 app:id/material_drawer_badge}
</code></pre>