Set a gradient background
<p>In my Activity I need to change an ImageView background using a gradient, so I use an image with a transparent area, changing its background when I need. Here's some code:</p>

<pre><code>private static View myImage;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myActivityLayout);

    myImage = findViewById(R.id.myImageID);
}
</code></pre>

<p>[...]</p>

<pre><code>private void myImageUpdate() {
    GradientDrawable gradient;
    int[] colors = {0xFF00FF00, 0xFF0000FF};

    // I make some changes to these colors..

    gradient = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, colors);
    myImage.setBackgroundDrawable(gradient);
}
</code></pre>

<p>Now, the problem is:
If I call myImageUpdate() within onCreate() method, everything works fine.
If I call myImageUpdate() from another part of the code (like an onClick callback), I can't set my backgroud!</p>

<p><strong>* UPDATE *</strong>
Guys, this code is fine... I was calling my method in a wrong (not directly reachable) line! My apologies...</p>
