Text Shadow
- Shadow for the text can also be given in Android. The attributes required for the shadowed text view are:
android:shadowDx=”integer_value” -> which decides the distance of text from its shadow with respect to x axis, if the integer_value is positive the shadow is on positive of the x axis and vice versa.
android:shadowDy=”integer_value” -> which decides the distance of text from its shadow with respect to y axis, if the integer_value is positive the shadow is on negative of the y axis and vice versa.
android:shadowRadius=”integer_value” -> which decides the amount of the shadow to be given for the text view.
Refer to the following code and its output for better understanding.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
tools:ignore="HardcodedText">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:shadowColor="@color/grey"
android:shadowDx="4"
android:shadowDy="4"
android:shadowRadius="10"
android:text="w3wiki"
android:textColor="#000000"
android:textSize="32sp"
tools:targetApi="ice_cream_sandwich" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:padding="8dp"
android:shadowColor="@color/grey"
android:shadowDx="-15"
android:shadowDy="4"
android:shadowRadius="10"
android:text="w3wiki"
android:textColor="#000000"
android:textSize="32sp"
tools:targetApi="ice_cream_sandwich" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:shadowColor="@color/grey"
android:shadowDx="4"
android:shadowDy="-15"
android:shadowRadius="10"
android:text="w3wiki"
android:textColor="#000000"
android:textSize="32sp"
tools:targetApi="ice_cream_sandwich" />
</LinearLayout>
Output:
Working With the TextView in Android
TextView in Android is one of the basic and important UI elements. This plays a very important role in the UI experience and depends on how the information is displayed to the user. This TextView widget in Android can be dynamized in various contexts. For example, if the important part of the information is to be highlighted then the substring that contains, it is to be italicized or it has to be made bold, one more scenario is where if the information in TextView contains a hyperlink that directs to a particular web URL then it has to be spanned with hyperlink and has to be underlined.
Contact Us