How to design custom EditText without box and with Underline ?

主宰稳场 提交于 2019-12-11 02:30:03

问题


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



来源:https://stackoverflow.com/questions/22195770/how-to-design-custom-edittext-without-box-and-with-underline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!