2017-03-02 33 views

回答

0

這是不可能的默認EditText,你需要找出任何自定義庫使用這種類型的功能與EditText

0

您可以使用自定義EditText(如下所示)(複製自here)執行此操作。

public class LinedEditText extends EditText { 
    private Paint mPaint = new Paint(); 

    public LinedEditText(Context context) { 
     super(context); 
     initPaint(); 
    } 

    public LinedEditText(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     initPaint(); 
    } 

    public LinedEditText(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     initPaint(); 
    } 

    private void initPaint() { 
     mPaint.setStyle(Paint.Style.STROKE); 
     mPaint.setColor(0x80000000); 
    } 

    @Override protected void onDraw(Canvas canvas) { 
     int left = getLeft(); 
     int right = getRight(); 
     int paddingTop = getPaddingTop(); 
     int paddingBottom = getPaddingBottom(); 
     int paddingLeft = getPaddingLeft(); 
     int paddingRight = getPaddingRight(); 
     int height = getHeight(); 
     int lineHeight = getLineHeight(); 
     int count = (height-paddingTop-paddingBottom)/lineHeight; 

     for (int i = 0; i < count; i++) { 
      int baseline = lineHeight * (i+1) + paddingTop; 
      canvas.drawLine(left+paddingLeft, baseline, right-paddingRight, baseline, mPaint); 
     } 

     super.onDraw(canvas); 
    } 
}