如何设计无框和下划线定制的EditText? [英] How to design custom EditText without box and with Underline ?
本文介绍了如何设计无框和下划线定制的EditText?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在开发Android应用。我也设计了的EditText在我的应用程序看到图像(4.2.2默认编辑文本)
I am developing apps in android. I did design for edittext in my apps see image (default edit text in 4.2.2)
我要的EditText风格像下面的图片
I want edittext style like following image
没有任何人有解决办法吗?
Does anybody have solution ?
推荐答案
创建扩展的EditText,CustomEditText code是波纹管:
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);
}
在XML中,把你的新CustomEditText代替的EditText的
In xml, put your new CustomEditText instead of EditText
这篇关于如何设计无框和下划线定制的EditText?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文