bd104529-c13f-376e-9e3c-f1176d0d46ce  

public class UnderlineEditText extends EditText {
private static final String TAG = "UnderlineEditText";
private Paint mPaint;
private Rect mRect;
private float mult = 1.5f;
private float add = 2.0f;

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

public UnderlineEditText(Context context) {
super(context);
init();
}

private void init() {
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.GRAY);
mPaint.setAntiAlias(true);
this.setLineSpacing(add, mult);
}

@Override
public void onDraw(Canvas canvas) {
Log.d(TAG, "func [onDraw]");
int count = getLineCount();
for (int i = 0; i < count; i++) {
getLineBounds(i, mRect);
int baseline = (i + 1) * getLineHeight();
canvas.drawLine(mRect.left, baseline, mRect.right, baseline, mPaint);
}
super.onDraw(canvas);
}

}

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()