Friday, May 22, 2015

How to apply shadow effect on a TextView text in Android

activity_main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".MainActivity"
    android:background="@android:color/white"
    >
    <!--
        android:shadowColor
            Place a blurred shadow of text underneath the text, drawn with the specified color.
        android:shadowDx
            Horizontal offset of the text shadow.
            Must be a floating point value, such as "1.2".
        android:shadowDy
            Vertical offset of the text shadow.
            Must be a floating point value, such as "1.2".
        android:shadowRadius
            Blur radius of the text shadow.
            Must be a floating point value, such as "1.2".
    -->
    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sample TextView..."
        android:textSize="30dp"
        android:textStyle="bold"
        android:textColor="#fffa2bff"
        android:shadowColor="#ff6cc450"
        android:shadowRadius="5"
        android:shadowDy="-5"
        />
    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv"
        android:text="Sample TextView..."
        android:textSize="30dp"
        android:textStyle="bold"
        android:textColor="#fffa2bff"
        android:shadowColor="#ff6cc450"
        android:shadowRadius="5"
        android:shadowDy="5"
        />
    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv2"
        android:text="Sample TextView..."
        android:textSize="30dp"
        android:textStyle="bold"
        android:textColor="#fffa2bff"
        android:shadowColor="#ff6cc450"
        android:shadowRadius="5"
        android:shadowDx="5"
        />
    <TextView
        android:id="@+id/tv4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv3"
        android:text="Sample TextView..."
        android:textSize="30dp"
        android:textStyle="bold"
        android:textColor="#fffa2bff"
        android:shadowColor="#ff6cc450"
        android:shadowRadius="5"
        android:shadowDx="-5"
        />
    <TextView
        android:id="@+id/tv5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv4"
        android:text="Sample TextView..."
        android:textSize="30dp"
        android:textStyle="bold"
        android:textColor="#fffa2bff"
        android:shadowColor="#ff6cc450"
        android:shadowRadius="5"
        android:shadowDy="5"
        android:shadowDx="5"
        />
</RelativeLayout>
More android examples