2
有沒有辦法讓多行edittext中的所有行加下劃線? 我希望所有行都能顯示行,即使沒有文字。Android - edittext - underline
有沒有辦法讓多行edittext中的所有行加下劃線? 我希望所有行都能顯示行,即使沒有文字。Android - edittext - underline
這種事情在Notepad示例演示中完成。如果我們看一下editor source,我們可以看到他們使用定製的文本編輯器,像這樣:
/**
* 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);
}
}
,他們隨後在layout聲明是這樣的:
<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" />
非常好... ...完美的作品...感謝您的幫助 – Noman 2012-12-13 13:07:31
我如何獲得寫在這個視圖上的文字? – Noman 2012-12-17 09:51:09