Ahmad
Ahmad

Reputation: 59

How to Create Line Drawable On Android

How to Create Drawable on Android look Like text below:

Remove

Upvotes: 0

Views: 2065

Answers (2)

Parsania Hardik
Parsania Hardik

Reputation: 4623

You can do something like this:

Programatically:

 TextView tv = (TextView) findViewById(R.id.mytext);
    tv.setText("Remove");
    tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

From xml file:

    <RelativeLayout
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           >
     <TextView
           android:id="@+id/textView2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Remove"
           />
     <View
           android:layout_width="fill_parent"
           android:layout_height="1dp"
           android:background="@color/black"
           android:layout_centerVertical="true"
            />
</RelativeLayout>

Upvotes: 0

user5248371
user5248371

Reputation:

for single word we can use drawable. Following is the example:

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

    <item android:state_pressed="false"><shape android:shape="line">
            <stroke android:width="2dp" android:color="#ffffff" />
        </shape>
    </item>

</selector>

for multiple line use below:-

TextView tv=(TextView) v.findViewById(android.R.id.text1);
tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

use your reference instead of "tv"

Upvotes: 1

Related Questions