• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Java Animated linear gradient background - Java


New Coder
Hello apologies if this is the wrong place, site or manner to ask questions. I am new to this and this is the first question I have ever asked.

I am trying to create an app in android studio and have created some content on it so far but have been toying with the background gradient. I have followed a guide to setup three different gradients and created animated gradient files as well as manipulating the javascript for the MainActivity.java. I created the app with a navigation side bar and so the code in the javascript is not the same as the default blank app in all the discriptions.

public class MainActivity extends AppCompatActivity {

    private AppBarConfiguration mAppBarConfiguration;
    private ConstraintLayout drawerLayout;
    private AnimationDrawable animationDrawable;

    protected void onCreate(Bundle savedInstanceState) {

        Toolbar toolbar = findViewById(R.id.toolbar);
        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();

                ConstraintLayout constraintLayout = findViewById(R.id.drawer_layout);
                AnimationDrawable animationDrawable = (AnimationDrawable) constraintLayout.getBackground();
I have kept the id in the activity_main.xml as drawer_layout which was how it setup by default. When i move the code block for the animation above the toolbar toolbar coding it crashes the app.

Basically in its current form the app sticks on the start gradient but doesnt transition to the center gradient or end gradient. I have tried numerous edits and have ensured the linear gradient is a multiple of 45.

Any help or advice greatly appreciated.

Kind Regards
Last edited by a moderator:


Active Coder
Hey there.

Unfortunately, I don't know how to build Android apps so I cannot help you with this. But, I have edited your question as so that the code is formatted and can easily be read.

Please remember to format your code for any future questions you may have - It saves us staff-members a lot of time and resources to not be going about formatting people's posts. Refer to this thread for help in the future: https://www.codeforum.org/threads/how-to-post-your-code-into-threads.183/
Top Bottom