我试图在EditText中覆盖ondraw,使用canvas在EditText上写单词。 但是当我在EditText中设置setInputType时,它无法显示任何单词。 我不知道它是如何运作的。
public class Input extends EditText{
private static int paddingHintText = 30;
private static int paddingInput = 200;
private static int hintTextSize = 40;
private String textString = "test";
Paint paint;
public Input(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
setBackgroundResource(R.drawable.editseletor);
setPadding(paddingInput, 0, 0, 0);
setGravity(Gravity.CENTER);
//if I use it,it can't display any words
//setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
paint = new Paint();
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
paint.setColor(Color.rgb(50, 50, 50));
paint.setTextSize(hintTextSize);
canvas.drawText(textString, paddingHintText, this.getHeight()/2+hintTextSize/2-5, paint);
canvas.drawLine(0, 50, 200, 50, paint);
super.onDraw(canvas);
}
public void setLeftText(String textString){
this.textString = textString;
}
}