Android
Text Shadow
Android Development
User Interface
Mobile Design

Shadow Effect for a Text in Android?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Android text shadows are a simple visual effect, but the details matter if you want the result to look intentional rather than muddy. A good shadow improves contrast or adds depth, while a bad one makes text blurrier and harder to read.

Using XML Attributes On TextView

For static UI, the easiest approach is to declare the shadow directly in layout XML.

xml
1<TextView
2    android:layout_width="wrap_content"
3    android:layout_height="wrap_content"
4    android:text="Hello"
5    android:textSize="24sp"
6    android:textColor="#FFFFFF"
7    android:shadowColor="#66000000"
8    android:shadowDx="2"
9    android:shadowDy="2"
10    android:shadowRadius="3" />

The important attributes are:

  • 'shadowColor for the shadow color.'
  • 'shadowDx for horizontal offset.'
  • 'shadowDy for vertical offset.'
  • 'shadowRadius for blur.'

These values are applied by the TextView when it renders the text.

Setting The Shadow In Code

If the effect depends on runtime state, use setShadowLayer.

kotlin
1val title = findViewById<TextView>(R.id.title)
2title.setShadowLayer(
3    3f,
4    2f,
5    2f,
6    0x66000000
7)

This is useful when the theme changes, the background changes, or you want to adjust the effect dynamically in response to user interaction.

How To Tune The Effect

Small values usually look better than dramatic ones. A huge blur radius or large offset can make the text feel fuzzy instead of polished.

A practical starting point is:

  • Low blur radius.
  • Small positive offset.
  • Semi-transparent dark shadow for light text.
  • Semi-transparent light shadow for dark text on very dark backgrounds.

You should always tune the shadow against the actual background the text will sit on. A shadow that looks great on a screenshot may look wrong once gradients, images, or animations are present.

Performance And Readability

One or two shadows on key labels are usually fine, but very heavy effects on many text views can make the UI feel visually noisy and can add rendering cost.

The main risk is readability. If the shadow color is too strong or the blur is too large, users no longer see crisp text. In accessibility-sensitive UI, clarity matters more than decorative depth.

If you need density-aware control in code, calculate the offsets intentionally instead of guessing raw pixel values. A tiny helper can convert dp-like design values into pixels before calling setShadowLayer, which makes the effect more predictable across different screens and text sizes. That is especially useful when designers specify visual spacing rather than literal pixel numbers.

Shadows are also easier to judge on real devices than in the layout preview alone. Preview tools can help with rough tuning, but final decisions should be tested against the actual screen density, font rendering, and background artwork your users will see. That small validation step prevents a lot of over-styled text from reaching production.

A subtle shadow usually ages better than a dramatic one as the app theme evolves.

That restraint usually improves both readability and polish.

Common Pitfalls

One common mistake is pushing the blur radius too high. That turns the effect from a shadow into a halo and can reduce legibility.

Another mistake is choosing a shadow color without testing it against the real background. The same settings can look excellent on one screen and poor on another.

A third issue is using shadows to compensate for weak color contrast. If text needs a shadow just to be barely readable, the base color design may need work first.

Summary

  • Android text shadows are easiest to apply with TextView XML attributes or setShadowLayer in code.
  • Subtle shadows usually look better than large, dramatic ones.
  • Tune shadow color, offset, and blur against the actual background, not in isolation.
  • Use shadows to support readability and depth, not to hide poor text contrast choices.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.