Android Studio – Animated Gradient Background

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;  @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

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.