帶下劃線的TextVeiw

帶下劃線的TextView,So easy!

/**
 * 帶有下劃線的TextView。
 */
public class UnderlineTextView extends TextView {

    public UnderlineTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public UnderlineTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public UnderlineTextView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        this.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        this.getPaint().setAntiAlias(true); //必須加上這句代碼,否則添加下劃線的代碼不起作用,不知道什麼原因?
        super.onDraw(canvas);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章