Search code examples
androidandroid-drawablexml-drawable

How to Create Line Drawable On Android


How to Create Drawable on Android look Like text below:

Remove


Solution

  • 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"