Android Question LinedEditText

D

Deleted member 103

Guest
Hi,

can someone help me?
I have found this code and want to use either with directly B4a or convert it to a library.

B4X:
Public class LinedEditText extends EditText {
    Private Rect mRect;
    Private Paint mPaint;

// we need this constructor For LayoutInflater
   Public LinedEditText(Context context, AttributeSet attrs) {
    super(context, attrs);

    mRect = new Rect();
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaint.setColor(R.color.edit_note_line); //SET YOUR OWN COLOR HERE
}

@Override
protected void onDraw(Canvas canvas) {
    //int count = getLineCount();

    int height = getHeight();
    int line_height = getLineHeight();

    int count = height / line_height;

    If (getLineCount() > count)
        count = getLineCount();//For long text with scrolling

    Rect r = mRect;
    Paint paint = mPaint;
    int baseline = getLineBounds(0, r);//first line

    For (int i = 0; i < count; i++) {

        canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
        baseline += getLineHeight();//Next line
    }

    super.onDraw(canvas);
    }
}
 
D

Deleted member 103

Guest
It is no longer necessary, I solved it with B4A. :)
It would nevertheless be interesting to know how that can be used for B4a.

B4X:
Private Sub CreateLine
    cv.Initialize(txtNotiz)
    cv.DrawColor(Colors.Transparent)
    For i = 0 To txtNotiz.Height Step lineHeight
        cv.DrawLine(5dip, lineHeight + 5dip + i, txtNotiz.Width - 5dip, lineHeight + 5dip + i, Colors.Gray, 1dip)
    Next
End Sub

edittext.png
 
Upvote 0
Top