MobII Lab1
MobII Lab1
Create different gradient xml files which are to be changed in the background. These files include startColor which is
shown in above part, endColor which is shown in lower part and angle of the horizontal line which divides both the part.
Here we create three gradient xml files.
1. Create a gradient_one.xml file in the Drawable folder and add the following code.
Create A New XML
gradient_one.xml
Add code to xml file
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/andr
oid">
<gradient
android:angle="225"
android:endColor="#09CCC8"
android:startColor="#ffd6d3" />
</shape>
2.Create a gradient_two.xml Create a gradient_two.xml file in the Drawable folder
and add the following code.
Create 2nd XML
gradient_two.xml
Create a gradient_three.xml file in the Drawable folder
3.Create a gradient_three.xml
gradient_three.xml
gradient_two ,three.xml
gradient_three.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="135"
android:endColor="#26F30F" gradient_two.xml
android:startColor="#F6F8F0" /> <?xml version="1.0" encoding="utf-8"?>
</shape> <shape
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="45"
android:endColor="#FD7BCE"
android:startColor="#A4DDF8" />
</shape>
Step 2: Create a gradient_list.xml file in the drawable folder
and add the following code. In this file we add all our
Step 2: Create a gradient_list.xml gradient xml files that we want to display and their duration.
gradient_list.xml
gradient_list.xml
gradient_list.xml
<item android:drawable="@drawable/gradient_one"
android:duration="3000"/>
<item android:drawable="@drawable/gradient_three"
android:duration="3000"/>
<item android:drawable="@drawable/gradient_two"
android:duration="3000"/>
</animation-list>
Step 3: Now add the following code in the activity_main.xml
Step 3: activity_main.xml file. In this file we add our gradient_list to the background of
our layout. activity_main.xml
activity_main.xml <?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/layout"
android:background="@drawable/gradient_list"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="#219806"
android:text=“Catholic University –IT CS Dep"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Now add the following code in the MainActivity.java file. From