Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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

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!

Back
Top Bottom