Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inner shadow on Android TextView

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

http://i.stack.imgur.com/88Mxd.png

Thanks !

like image 348
alxscms Avatar asked Nov 01 '11 11:11

alxscms


People also ask

How to add shadow to Android studio Text?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above tags indicates about shadow color, Axis's(X, Y) and shadow radius for text view.

What are Android shadows?

Shadows are drawn by the parent of the elevated view, and thus subject to standard view clipping, clipped by the parent by default. Elevation is also useful to create animations where widgets temporarily rise above the view plane when performing some action.

How do you animate Textview?

To start the animation we need to call the startAnimation() function on the UI element as shown in the snippet below: sampleTextView. startAnimation(animation); Here we perform the animation on a textview component by passing the type of Animation as the parameter.


3 Answers

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?

like image 71
ABentSpoon Avatar answered Oct 16 '22 16:10

ABentSpoon


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

like image 39
Nibha Jain Avatar answered Oct 16 '22 18:10

Nibha Jain


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.

like image 38
Romain Piel Avatar answered Oct 16 '22 17:10

Romain Piel