Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An EditText with under lines.
public class LinedEditText extends {
private Rect mRect;
private Paint mPaint;
public LinedEditText(Context context, AttributeSet attrs) {
super(context, attrs);
mRect = new Rect();
mPaint = new Paint();
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();
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.