Kotlin startColor endColor : GradientDrawable (_header.xml):
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:angle="180"
android:startColor="@color/StartColor"
android:endColor="@color/EndColor"
android:type="linear" />
<corners
android:radius="0dp"/>
View (ViewGroup), XML (ly_custom_header.xml):
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:background="@drawable/gradient_header"
android:layout_height="80dp"
android:id="@+id/rootConstraintLayout">
1- XML (: ly_custom_header), /:
val layoutFile = View.inflate(this, R.layout.ly_custom_header, null)
* , .
2- ViewwGroup (ConstraintLayout, LinearLayout,...), XML, , - ConstraintLayout:
val rootConstraintLayout= layoutFile.findViewById< ViewGroup >(R.id.root_constraintlayout_ly_custom_header)
3- GradientDrawable Gradient Drawable:
var drawable = rootConstraintLayout.background as GradientDrawable
4- / :
drawable.colors = intArrayOf( startColor , endColor )
5- ( ConstraintLayout):
rootConstraintLayout.background = drawable