idengpan
idengpan

Reputation: 41

TextView can't set drawableLeft(or Top,Right,Bottom) with Shape drawable?

I defined a shape drawable ,it's a line.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke android:color="#f00" android:width="2dp"/>
</shape>

and then I set this shape in TextView's drawableBottom,but it didn't work.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:drawableBottom="@drawable/shape_line"
    android:drawablePadding="5dip"
    android:text="Hello World" />

why and how can let it work?

Upvotes: 3

Views: 2319

Answers (2)

Nguyễn Trung Hiếu
Nguyễn Trung Hiếu

Reputation: 2032

Try this!!!!

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<size
    android:height="1dp"
    android:width="500dp" />

<solid android:color="#f00" />

</shape>

Upvotes: 6

fsebek
fsebek

Reputation: 389

One solution is to just add a separate view below the textview. Since you just want a line add a View and set the height to 2dp and the background color to #f00

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:drawableBottom="@drawable/shape_line"
    android:drawablePadding="5dip"
    android:text="Hello World" />

<View
    android:layout_width="wrap_content"
    android:layout_height="2dp"
    //set your custom color
</View>

Upvotes: 0

Related Questions