Android - Jak podkreślić wszystkie linie w edytorze tekstu?

Z samouczka stworzyłem układ:

<code>  public static 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.STROKE);
            mPaint.setColor(0x80000000);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            int count = getLineCount();
            Rect r = mRect;
            Paint paint = mPaint;

            for (int i = 0; i < count; i++) {
                int baseline = getLineBounds(i, r);
                canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
            }

            super.onDraw(canvas);
        }
    }

<view xmlns:android="http://schemas.android.com/apk/res/android"
    class="com.bbbfr.mynotepad.NotepadText$LinedEditText"
    android:id="@+id/note"
    android:background="#ffd6e5"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp"
    android:scrollbars="vertical"
    android:fadingEdge="vertical"
    android:gravity="top"
    android:textSize="22sp"
    android:textColor="#000000"
    android:inputType="textMultiLine"
    android:capitalize="sentences"
/>
</code>

Powoduje to podkreślenie tylko pierwszej linii. Czy możliwe jest podkreślenie wszystkich linii, nawet jeśli edtittext ma tylko jedną linię?

Próbowałem zmienić pętlę np.for (int i = 0; i < 5; i++) ale wtedy otrzymuję ten błąd:

04-28 08: 29: 05.093: E / AndroidRuntime (14398): java.lang.IndexOutOfBoundsException: 2, 1 04-28 08: 29: 05.093: E / AndroidRuntime (14398): w android.text.PackedIntVector.getValue ( PackedIntVector.java:70) 04-28 08: 29: 05.093: E / AndroidRuntime (14398): na android.text.DynamicLayout.getLineTop (DynamicLayout.java:367) 04-28 08: 29: 05.093: E / AndroidRuntime ( 14398): w android.text.Layout.getLineBottom (Layout.java:831) 04-28 08: 29: 05.093: E / AndroidRuntime (14398): w android.text.Layout.getLineBounds (Layout.java:437) 04 -28 08: 29: 05.093: E / AndroidRuntime (14398): w android.widget.TextView.getLineBounds (TextView.java:4122) 04-28 08: 29: 05.093: E / AndroidRuntime (14398): w com.bbbfr .mynotepad.NotepadText $ LinedEditText.onDraw (NotepadText.java:56)

do tej linii:int baseline = getLineBounds(i, r);

Ja także ustawiłemandroid:lines="5" w widoku.

questionAnswers(3)

yourAnswerToTheQuestion