我在android中开发应用程序。我在我的应用程序中设计了edittext,参见图像(4.2.2中的默认编辑文本)
我想要编辑文字样式,如下图
有人有解决方案吗?
答案 0 :(得分:4)
创建扩展EditText的CustomEditText,代码如下:
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
答案 1 :(得分:1)
你应该尝试