inner shadow on Android TextView
Asked Answered
E

3

7

is it possible to put an inner shadow on the text of a TextView in Android like this one :

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpKnMxcF_AZVLQamyA/88Mxd.png

Thanks !

Euthenics answered 1/11, 2011 at 11:26 Comment(0)
T
1

That's a duplicate to a question I asked a few months ago: Is there a way to add inner shadow to a TextView on Android?

No proper way to do that at the moment. But if you try playing with the alpha of the text color and the drop shadow you can end up having something close to an inner shadow.

Timbre answered 1/11, 2011 at 11:40 Comment(2)
Ok thanks, I already see your post but I thought you asked for the nine-patch.Euthenics
Can you elaborate on "playing with the alpha of the text color and the drop shadow"? The question you link to doesn't contain the answer to this question.Gotama
C
7

MagicTextView will do inner shadows.

enter image description here

    <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?

Charissa answered 24/4, 2012 at 8:2 Comment(2)
I would not recommend MagicTextView as it is designed right now. The solution will cause an infinite invalidation loop and have huge impact on performance. As the layout will never settle you cannot rely on things like waitForIdleSync in Instrumentation either.Fransen
I actually fixed that problem a while back. The invlaidate/postInvalidate methods are disabled while the draw is in progress. That was a pretty big performance killer though.Charissa
I
2

For Shadowing effect :

 <TextView
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="5sp"
    android:paddingTop="15sp"
    android:paddingBottom="15sp"
    android:typeface="normal"
    android:text="I'm normal (bold) font but I have a shadow"
    android:textSize="16sp"
    android:textStyle="bold"
    android:shadowColor ="#0f0f0f"
    android:shadowRadius="1.6"
    android:shadowDx="1.5"
    android:shadowDy="1.3"
    android:textColor="#000000"
    android:background="#ffffff"
    />

Or ,You can use your own Fonts , Place them in the res/assets folder :

TextView txt = (TextView) findViewById(R.id.custom_font);   
Typeface font = Typeface.createFromAsset(getAssets(), "my_font.ttf");  
txt.setTypeface(font);

Or check the following links for detail:

http://www.barebonescoder.com/2010/05/android-development-using-custom-fonts/

and

http://www.giantflyingsaucer.com/blog/?p=1421

Irresolute answered 1/11, 2011 at 11:38 Comment(2)
Yeah but i'm not sure to understand, how a new font can affect the text to have an inner shadow ?Euthenics
this properties is not inner shodowInquest
T
1

That's a duplicate to a question I asked a few months ago: Is there a way to add inner shadow to a TextView on Android?

No proper way to do that at the moment. But if you try playing with the alpha of the text color and the drop shadow you can end up having something close to an inner shadow.

Timbre answered 1/11, 2011 at 11:40 Comment(2)
Ok thanks, I already see your post but I thought you asked for the nine-patch.Euthenics
Can you elaborate on "playing with the alpha of the text color and the drop shadow"? The question you link to doesn't contain the answer to this question.Gotama

© 2022 - 2024 — McMap. All rights reserved.