Is there a way to add inner shadow to a TextView on Android?
Asked Answered
S

2

14

I would like to make an inner shadow on a textview, But I can't find any example of that on the web.

Is there any way to do that on Android?

I know these attributes:

android:shadowColor
android:shadowRadius
android:shadowDx
android:shadowDy

Am I missing something useful?

Stylo answered 29/7, 2011 at 9:46 Comment(1)
I just tried to set negative values to android:shadowDy android:shadowDx and android:shadowRadius but that doesn't solve anything. Any idea?Stylo
S
12

If you want the TextView to have inner shadow like this:

enter image description here

you have to use 9-patch drawable like this one:

enter image description here

Set the 9-patch drawable as the TextView's background.

The attributes you mention: android:shadowColor, android:shadowRadius, android:shadowDx, android:shadowDy serve other purpose, they create text shadow:

enter image description here

Staminody answered 19/9, 2011 at 10:43 Comment(2)
I downloaded and tested the image but it shows ugly. How to remove black lines? How do i modify to get engraved style textview? Thanks.Lelea
If you mean the image in the post. It's a 9-patch png. The black lines serve purpose. It will not work without them. Read the docs developer.android.com/guide/topics/graphics/… I don't think this will serve well for an engraved style text. I guess a special font, image or special view will be necessary for that.Staminody
T
21

If you're looking for inner shadows like these:

enter image description here

You could try MagicTextView

    <com.qwerjk.better_text.MagicTextView
        xmlns:qwerjk="http://schemas.android.com/apk/res/com.qwerjk.better_text"
        android:textSize="42dp"
        android:textColor="#FFffff00"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:padding="10dp"
        qwerjk:innerShadowDy="3"
        qwerjk:innerShadowColor="#FF000000"
        qwerjk:innerShadowRadius="5"
        android:text="InnerShadow" />

Note: I made this, and am posting more for the sake of future travelers than the OP. It's borderline spam, but being on-topic, perhaps acceptable?

Theodoretheodoric answered 24/4, 2012 at 8:13 Comment(3)
Nice breakthrough, which is still a problem in android. (inner shadow) is this only for text's or can be set for any views?Vaillancourt
I hadn't thought of making this work for other views. Usually, I just drop a View with a GradientDrawable background into a FrameLayout over the view I want shaded. Would be nice to only need to add an xml property though.Theodoretheodoric
It works fine on ICS and prev versions, but on Jelly Bean it doesn't work.Tutti
S
12

If you want the TextView to have inner shadow like this:

enter image description here

you have to use 9-patch drawable like this one:

enter image description here

Set the 9-patch drawable as the TextView's background.

The attributes you mention: android:shadowColor, android:shadowRadius, android:shadowDx, android:shadowDy serve other purpose, they create text shadow:

enter image description here

Staminody answered 19/9, 2011 at 10:43 Comment(2)
I downloaded and tested the image but it shows ugly. How to remove black lines? How do i modify to get engraved style textview? Thanks.Lelea
If you mean the image in the post. It's a 9-patch png. The black lines serve purpose. It will not work without them. Read the docs developer.android.com/guide/topics/graphics/… I don't think this will serve well for an engraved style text. I guess a special font, image or special view will be necessary for that.Staminody

© 2022 - 2024 — McMap. All rights reserved.