How to add shadow effect on text in Android Studio using Kotlin.

Last updated Dec 13, 2021

In this android example tutorial, we will see how to add shadow effect to text by using Kotlin in android studio.
 

Implementation:

To begin, Create a new project in android studio and enter the name, select the project location and language to Kotlin. Then press the Finish button.
Open the activity_shadow_effect_text.xml file and add the LinearLayout with orientation (Vertical or horizontal).

    <LinearLayout 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:orientation="vertical"
    android:gravity="center"
    android:background="#F4F4EB"
    tools:context=".ShadowEffectText">
</LinearLayout>

 

 In activity_shadow_effect_text.xml file, insert an TextView inside a LinearLayout.

       <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Kotlin Developer"
        android:textSize="29sp"
        android:textColor="@color/black"
        ></TextView>

 

For add shadow in text you have to use shadowColor , shadowDx and shadowDy property and set radius of radius by using shadowRadius attribute.

  android:shadowDx="8"
  android:shadowDy="6"
  android:shadowRadius="4"
  android:shadowColor="#D64A4A"


 

TextView in android has the following properties
    id, padding, textSize, text, textColor, shadowDy, shadowRadius, fontFamily, textStyle, layout_margin etc.

        android:padding="10dp"
        android:text="Kotlin Developer"
        android:textSize="29sp"
        android:textColor="#000"
        android:layout_margin="10dp"

 

Now run the application, you will see the output shown below.

 

Output:

Shade Effect on Text

 

 Complete source code  for Shadow Effect on Text Android example:
 

 activity_shadow_effect_text.xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:gravity="center"
    android:background="#F4F4EB"
    tools:context=".ShadowEffectText">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Kotlin Developer"
        android:textSize="29sp"
        android:textColor="@color/black"
        android:shadowDx="8"
        android:shadowDy="6"
        android:shadowRadius="4"
        android:shadowColor="#D64A4A"
        ></TextView>
</LinearLayout>

 

Conclusion: We have covered the topic how to add Shadow Effect on Text to Android by using Kotlin.
 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:gravity="center"
    android:background="#F4F4EB"
    tools:context=".ShadowEffectText">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Kotlin Developer"
        android:textSize="29sp"
        android:textColor="@color/black"
        android:shadowDx="8"
        android:shadowDy="6"
        android:shadowRadius="4"
        android:shadowColor="#D64A4A"
        ></TextView>
</LinearLayout>

 

Conclusion: We have covered the topic how to add Shadow Effect on Text to Android by using Kotlin.
 

 

-->
Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

1047 Views