Create seperates drawable color file and add to your drawable folder
example: color1 copy and past below code for each
<--color1-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#FF4081"
android:endColor="#0f3443"
android:angle="90" />
</shape>
<--color2-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#ffffff"
android:endColor="#191654"
android:angle="135"/>
</shape>
<--and so on-->
Create a drawable color file and add to your drawable folder
example: animation_colors.xml copy below file and past below code
<item android:drawable="@drawable/color1"
android:duration="9000"/>
<item android:drawable="@drawable/color2"
android:duration="9000"/>
In your activity activity_main.xml
add a background color and reference your drawable example: android:background="@drawable/animation_colors"
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ff"
android:background="@drawable/animation_colors"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
In your activity MainActivity.java
new BackgroundColorAnimation().
init(layout).// your activity xml
setEnterAnimDuration(500).// long
setExitAnimDuration(200).// long
start();
Overide some life circle methods
@Override
protected void onPause() {
super.onPause();
new BackgroundColorAnimation().stop();
}
@Override
protected void onResume() {
super.onResume();
new BackgroundColorAnimation().start();
}
}
Add in your build.gradle
project level file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add in your build.gradle
app level file
dependencies {
implementation 'com.github.Inihood1:Gradient-Color-Animation-Android:1.0.1'
}
Copyright 2020 Ini Hood
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.