Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Animated linear gradient background - Java

Mbaxter88

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.

Java:
public class MainActivity extends AppCompatActivity {

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

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


        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            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();
                animationDrawable.setEnterFadeDuration(10);
                animationDrawable.setExitFadeDuration(800);
                animationDrawable.start();
        }

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:
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/
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom