Edge
Edge

Reputation: 933

How do I Set the Shadow around TextView

<TextView
            android:id="@+id/text"
            android:layout_width="225dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_toRightOf="@+id/left"
            android:background="@anim/chatitemshaodow"
            android:fontFamily="calibri"
            android:padding="8dp"
            android:textColor="#636363"
            android:textSize="17dp" />

This is my TextView controls and I want set the shadow around TextView. I am able to set the Showdown on text in TextView but I am unable to set shadow round on TextView.

I want to set textview shadow like given Screen in android. enter image description here

Upvotes: 7

Views: 13668

Answers (3)

S HemaNandhini
S HemaNandhini

Reputation: 333

This was work for me

android:shadowRadius="3" android:shadowDy="-4"

Upvotes: 0

user3956566
user3956566

Reputation:

Create a new drawable resource file. I named mine two_sided_border.xml.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
<item>
    <shape>
        <solid android:color="@color/black" />
    </shape>
</item>
<!-- This is the main color -->
<item android:bottom="2dp" android:right="2dp">
    <shape>
        <solid android:color="@color/green" />
    </shape>
</item>
</layer-list>

Then use this as the background for your textview.

<TextView
    android:id="@+id/t"
    android:background="@drawable/two_sided_border"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"/>

Your colors and dimensions (padding, text size) can be tweaked to suit.

Two great links:

how to make stroke for 3 sides for a shape in android?

And borrowed some code from here:

Open-sided Android stroke?

ps the other answer provided by Basil Miller gives good way to set shadow for the actual text itself.

textview

Upvotes: 7

GIGAMOLE
GIGAMOLE

Reputation: 1266

Perhaps you'd consider using android:shadowColor, android:shadowDx, android:shadowDy, android:shadowRadius; alternatively setShadowLayer() ?

There is the style:

<style name="Text">
    <item name="android:paddingLeft">4px</item>
    <item name="android:paddingBottom">4px</item>
    <item name="android:textColor">#ffffffff</item>
    <item name="android:textSize">12sp</item>
    <item name="android:shadowColor">#000000</item>
    <item name="android:shadowDx">1</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">1</item>
  </style>

Method 1:

<TextView android:id="@+id/text"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       style="@style/Text"
       android:gravity="center" />

Method 2:

TextView text= (TextView) findViewById(R.id.text);
infoTextView.setTextAppearance(getApplicationContext(),  
       R.style.Text);

Upvotes: 2

Related Questions