La modification de la couleur dans une forme à l'intérieur d'une couche-liste par programmation

Je suis en train de modifier par programmation la couleur de la selectable_kachel_shape. Voici le fichier xml:

kachel_ticked_style.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >


    <item>
        <shape
            android:id="@+id/selectable_kachel_shape"
            android:shape="rectangle" >
            <stroke
                android:width="5dp"
                android:color="@color/headrbar_color" />
        </shape>
    </item>
    <item>
        <rotate
            android:fromDegrees="45"
            android:pivotX="120%"
            android:pivotY="100%"
            android:toDegrees="45" >
            <shape android:shape="line" >
                <stroke
                    android:width="40dp"
                    android:color="@color/headrbar_color" />
            </shape>
        </rotate>
    </item>
    <item
        android:right="5dp"
        android:top="5dp">
        <bitmap
            android:gravity="top|right"
            android:src="@drawable/selectable_tiles_check" />
    </item>

</layer-list>

Je fais appel à l'intérieur d'un Fragment de code suivant

LayerDrawable layers = (LayerDrawable)  this.getActivity().getResources().getDrawable(R.drawable.kachel_ticked_style);

GradientDrawable shape = (GradientDrawable) (layers.findDrawableByLayerId(R.id.selectable_kachel_shape));
                       shape.setColor(this.getActivity().getResources().getColor(android.R.color.background_dark);

1.Pourquoi suis-je geting un NullPointerException dans forme.setColor?

2.Comment serait-il possible de changer la couleur à l'intérieur d'une forme, c'est à l'intérieur d'une couche de liste, par programmation?

InformationsquelleAutor Stam | 2013-12-20