How to design custom EditText without box and with

2019-07-17 01:43发布

问题:

I am developing apps in android. I did design for edittext in my apps see image (default edit text in 4.2.2)

I want edittext style like following image

Does anybody have solution ?

回答1:

Create CustomEditText that extends EditText , code is bellow :

public class MyCustomEditText extends EditText {

private Rect mRect;
private Paint mPaint;

public MyCustomEditText (Context context, AttributeSet attrs) {
    super(context, attrs);
    mRect = new Rect();
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.STROKE);
    int aColor = Color.parseColor("#dedede");
    mPaint.setColor(aColor);
}

@Override
protected void onDraw(Canvas canvas) {
    int height = getHeight();
    int line_height = getLineHeight();
    int count = height / line_height;
    if(getLineCount() > count){
        count = getLineCount();
    }
    Rect r = mRect;
    Paint paint = mPaint;
    int baseline = getLineBounds(0, r);
    for (int i = 0; i < count-1; i++) {
        canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
        baseline += getLineHeight();
    }
    super.onDraw(canvas);
}

In xml, put your new CustomEditText instead of EditText



回答2:

you should to try

Holo Every where