笔记本样式的EditText控件(每行均带下划虚线)

package com.zongyi.trip.ui;





import com.zongyi.trip.R;





import android.annotation.SuppressLint;

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.DashPathEffect;

import android.graphics.Paint;

import android.graphics.PathEffect;

import android.util.AttributeSet;

import android.widget.EditText;





@SuppressLint({ "ResourceAsColor", "DrawAllocation" })

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); 

//    	mPaint.setStyle(Paint.Style.STROKE);  

//    	mPaint.setColor(R.color.dashed_line_color);         

//        PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1);  

//        mPaint.setPathEffect(effects);

    }





    @Override protected void onDraw(Canvas canvas) {

    	Paint mPaint = new Paint();

//       mPaint.setColor(0x80000000); 

    	mPaint.setStyle(Paint.Style.STROKE);  

    	mPaint.setColor(Color.LTGRAY); 

    	PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},5);  

      mPaint.setPathEffect(effects);

    	

        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 spcingHeight = (int) getLineSpacingExtra();

        int count = (height-paddingTop-paddingBottom) / lineHeight;

        

          





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

            int baseline = lineHeight * (i+1) + paddingTop - spcingHeight/2 ;

            canvas.drawLine(left+paddingLeft, baseline, right-paddingRight, baseline, mPaint);

        }





        super.onDraw(canvas);

    }

}
 <com.zongyi.trip.ui.LinedEditText

            android:id="@+id/edittext_message"

            android:layout_width="fill_parent"

            android:layout_height="200dp"

            android:lineSpacingExtra="15dp"

            android:gravity="top"

            android:textColor="#ACB6BB"

            android:textSize="18sp" />



笔记本样式的EditText控件(每行均带下划虚线)

你可能感兴趣的:(EditText)