Android : Strike out Text with bold or thicker line than default STRIKE_THRU_TEXT_FLAG

line through text in android
text cross line in android
how to strike text in textview android
strikethrough text one line
bold text android
how to strikethrough text samsung
how to remove strikethrough in android textview
strike out text unicode

I am using following for strike text.

 viewHolder.price_red.setPaintFlags(viewHolder.price_red
                    .getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

Its working but I want to increase size of strike through line.

Can anybody help me how to increase size of line ??

You can't change the thickness of the strikethrough line.

As you can see from the docs its just a flag. Either on or off.

There are a couple of options though (more hacks than solutions):

  1. Make the text bold or stroke it. This will automatically stroke the strikethrough too which will make it more visible

  2. Manually draw the line with drawLine. (This would be really difficult to do accurately though)

Android : Strike out Text with bold or thicker line than , I am using following for strike text. viewHolder.price_red.setPaintFlags(​viewHolder.price_red .getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); Its working  Android – How to Strike Through or Cross out a Text in Android This android tip is about learning how to strike through or cross out in text in android. We are going to learn the different options available to you.

This can not be achieved directly as Android doesn't provide any API for the same.

Now, you will have to go Custom way to draw the thicker line.. 1) DrawLine 2)Use Line Image over EditText

I have tried using a EditText and a ImageView under a RelativeLayout and it worked quite nicely for me.

XML Code :

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <EditText
            android:id="@+id/etStrike"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:text="Strike Thru Text Here"
            android:textColor="@color/blacktext"
            android:textSize="20sp" />

        <ImageView
            android:id="@+id/ivStrike"
            android:layout_width="wrap_content"
            android:layout_height="6dp"
            android:layout_centerInParent="true"
            android:background="@color/blacktext" />
    </RelativeLayout>

JAVA Code :

    EditText etStrike = (EditText)findViewById(R.id.etStrike);
    ImageView ivStrike = (ImageView)findViewById(R.id.ivStrike);

    float textSize = etStrike.getTextSize()/2;
    int textLength = etStrike.getText().length();
    int totalLengthApprox = (int) (textLength * textSize)-textLength;
    int height = 6; // YOUR_REQUIRED_HEIGHT

    RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(totalLengthApprox,height);
    param.addRule(RelativeLayout.CENTER_VERTICAL|RelativeLayout.ALIGN_PARENT_LEFT);
    param.setMargins((int)textSize, 0, 0, 0);
    ivStrike.setLayoutParams(param);

I have tested only a few TextSize and Device Resolutions and most important this can work only for singleline EditText for multiline the logic becomes more complex.

Android – How to Strike Through or Cross out a Text in Android, This android tip is about learning how to strike through or cross out in text in android. We are going You can also see my android tips on how to add dash-​line in android android:textStyle="bold" android:text="@string/sport_trainers" There is a limited edition so if you plan to buy it there is no other better time than now. As you can see from the docs its just a flag. Either on or off. There are a couple of options though (more hacks than solutions): Make the text bold or stroke it. This will automatically stroke the strikethrough too which will make it more visible. Manually draw the line with drawLine.

Here is how to go about it: use a layer-list and place as your textview background. Here i am assuming your textviews background is white (#FFFFFF)

create in the drawables folder a file called strikethru.xml:

 <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF"/> 
        </shape>
    </item>
    <item>
        <shape android:shape="line">
            <stroke android:width="1dp"
                android:color="#8d8d8d"/> <!-- adjust color you want here -->
        </shape>
    </item>
</layer-list>

then in your textview do this:

    <TextView
                                android:id="@+id/tv_toolbar_prod_price"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"

                                android:paddingRight="3dp"
                                android:text="1,290 B"      

android:background="@drawable/strikethru_line"
                                android:textColor="#070707"
                                android:textSize="13sp" />

the padding right of 3dp makes the strike through more evident.

android.widget.EditText.getTextSize java code examples, Android : Strike out Text with bold or thicker line than default STRIKE_THRU_TEXT_FLAG. EditText etStrike = (EditText)findViewById(R.id.​etStrike); ImageView  The Highlight Text, Cross Out Text, and Underline Text tools provide the same functionality and options that are available with the Text Edits tool, but with easier access. If you want to delete the highlighted, crossed-out, or underlined formatting to your text, just click the formatted area and hit the Delete or Backspace key.

android - creating a strikethrough text?, Can I create a strikethrough text in Android, I mean adding a special value in the TextView android:typeface="sans" android:textSize="12dip" android:textStyle="​bold"/> "ipsum" (characters 6 to 11) one and a half time bigger than the textbox text. android:shape="line"> <stroke android:width="2dp" android:color="#ffffff"  Can you do bold text on whole sentences or do I have to do asterisk’s on every word on youtube just to highlight a main point for eg. I went to the shop today. *I went to the shop today*. I did this on youtube just to make the sentences come out in bold but this did not work. *I*went*to*the*shop*today*.

Paint, Create a new paint with default settings. Returns the thickness of the strike-​through line in pixels. Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set Enabling this flag will cause text draw operations to apply a simulated bold effect when drawing a Typeface that is not already  Apply or remove strikethrough or double strikethrough text formatting. To remove double-line strikethrough formatting, select the text, and then go to Home and select Strikethrough twice in the Font group.

4 Android TextView StrikeThrough XML & 2 Kotlin/Java Examples , You might have seen strikethrough text in websites or apps. a text. Here, I have discussed 4 Android TextView StrikeThrough XML and 2 Java/Kotlin examples. STRIKE_THRU_TEXT_FLAG; textview2.text = "2. <shape android:shape="line"​>; <stroke android:width="1dp" android:color="#fa460a">  Just select the portion of the word document you want to strike through, click Control+D then font dialogue box opens and then go to strike through box below and click it. That's enough, the selected portion is struck through by a line.

Comments
  • By size do you mean thickness?
  • @CarlSaldanha yes thickness of line.
  • Thanks @carl its helpful answer.. +1 for give solutions also.