Android的 - 的EditText - 下划线 [英] Android - edittext - underline

查看:312
本文介绍了Android的 - 的EditText - 下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,使强调了多行的EditText所有行? 我希望所有的线,显示线,即使有上面​​没有文字。

Is there a way to make all lines in a multi-line edittext underlined? I want all lines to show the line, even if there's no text on it.

推荐答案

这样的事情是在的记事本样品演示。如果我们看一下<一href="http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NoteEditor.html">editor来源,我们可以看到,他们使用自定义的文本编辑器,像这样的:

This sort of thing is done in the Notepad sample demo. If we look at the editor source, we can see they use a custom text editor, like this :

/**
 * A custom EditText that draws lines between each line of text that is displayed.
 */
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(0x800000FF);
    }

    @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.example.android.notepad.NoteEditor$LinedEditText"
    android:id="@+id/note"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent"
    android:padding="5dp"
    android:scrollbars="vertical"
    android:fadingEdge="vertical"
    android:gravity="top"
    android:textSize="22sp"
    android:capitalize="sentences" />

这篇关于Android的 - 的EditText - 下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆