gradient in android studio

// Step 1: Open your XML layout file (e.g., activity_main.xml) and add a View element where you want the gradient.

// Step 2: Define the gradient in the res/drawable folder by creating an XML file (e.g., gradient_background.xml).

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#FF0000"   // Specify the starting color
        android:endColor="#0000FF"     // Specify the ending color
        android:angle="45"/>           // Specify the angle of the gradient
</shape>

// Step 3: Apply the gradient as the background of the View in your XML layout file.

<View
    android:id="@+id/yourViewId"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/gradient_background"/>

// Step 4: In your Kotlin code, access the View and set its background to the gradient.

val yourView = findViewById<View>(R.id.yourViewId)
yourView.setBackgroundResource(R.drawable.gradient_background)