Open top menu

In this tutorial implements the example strikethrough programmatically.


Activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:padding="16dp"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="15dp"
        android:text="Example: textview strikethrough programmatically"
        android:textSize="25dp" />

    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv"
        android:text="Strike Through" />

</RelativeLayout>



MainActivity.java

package com.androidbeginner.testcode;

import android.app.Activity;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.registration_form);

              final TextView tv = (TextView) findViewById(R.id.tv);
              Button btn = (Button) findViewById(R.id.btn);

              btn.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {

                           tv.setPaintFlags(tv.getPaintFlags()
                                         | Paint.STRIKE_THRU_TEXT_FLAG);
                     }
              });
       }

}







Tagged

0 comments