1. 程式人生 > >android字型帶下劃線

android字型帶下劃線

介面佈局檔案程式碼:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/tv"
        android:textSize="64sp"
        android:text="hello"
        android:textStyle="bold"
        android:textColor="#000000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

java程式碼:
public class MainActivity extends Activity {

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

    private void init() {
        TextView tv = (TextView)findViewById(R.id.tv);
        tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG );
    }
}

效果: