Android开发教程:动态添加控件(2)

自定义的EditText控件:

package com.mrzhu.edittest;

import Android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.EditText;

public class EditTextTest extends EditText {

public EditTextTest(Context context) {
  super(context);
 }
 
 public EditTextTest(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
 }

public EditTextTest(Context context, AttributeSet attrs) {
  super(context, attrs);
 }

@Override
 protected void onDraw(Canvas canvas) {
  Paint paint = new Paint();
  paint.setTextSize(20);
  paint.setColor(Color.GRAY);
  canvas.drawText("输入提示文本:", 10, getHeight() / 2 + 5, paint);
  super.onDraw(canvas);
 }
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/c33d7c08b5939aeb2a455b5888b81b97.html