XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp">
<!--给文字添加中划线-->
<TextView
android:id="@+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="给文字添加中划线"
android:textSize="30sp"
android:textColor="#00dd99"
android:layout_marginTop="15dp"/>
<!--给文字添加下划线-->
<TextView
android:id="@+id/TextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="给文字添加下划线"
android:textSize="30sp"
android:textColor="#00dd99"
android:layout_marginTop="15dp"/>
</LinearLayout>
Activity:
package com.example.prize.mydemo1;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class Main5Activity extends AppCompatActivity {
TextView textView1,textView2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main5);
textView1 = (TextView)findViewById(R.id.TextView1);
textView2 =(TextView)findViewById(R.id.TextView2);
textView1.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//中划线
textView1.getPaint().setAntiAlias(true); //去掉锯齿
textView2.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
}
}
运行效果: