Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An EditText with under lines.
public class LinedEditText extends android.support.v7.widget.AppCompatEditText {
private Rect mRect;
private Paint mPaint;
public LinedEditText(Context context, AttributeSet attrs) {
super(context, attrs);
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setColor(Color.GRAY);
}
@Override
protected void onDraw(Canvas canvas) {
int height = getHeight();
int lineHeight = getLineHeight();
int linesCount = height / lineHeight;
if (getLineCount() > linesCount) {
linesCount = getLineCount();
}
Rect r = mRect;
Paint paint = mPaint;
/*Base first line.*/
int baseline = getLineBounds(0, r);
/*Draw remaining lines.*/
for (int i = 0; i < linesCount; ++i) {
canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
baseline += getLineHeight();
}
super.onDraw(canvas);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.