帶下劃線的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);
}
}