所谓自定义控件(或称组件)也就是编写自己的控件类型,而非Android中提供的标准的控件,如TextView,CheckBox等等.不过自定义的控件一般也都是从标准控件继承来的,或者是多种控件组合,或者是对标准控件的属性进行改变而得到的自己满意的控件.
定义自己的控件类:--------------------------------------------代码1.
com.android.tutor;
android.content.Context;
android.content.res.TypedArray;
android.graphics.Canvas;
android.graphics.Color;
android.graphics.Paint;
android.graphics.Rect;
android.graphics.Paint.Style;
android.util.AttributeSet;
android.view.View;
class MyView extends View
Paint mPaint;
Context mContext;
static final String mString = "Welcome to Mr Wei's blog";
MyView(Context context)
= new Paint();
MyView(Context context,AttributeSet attrs)
= new Paint();
a = context.obtainStyledAttributes(attrs,R.styleable.MyView);
textColor = a.getColor(R.styleable.MyView_textColor,0XFFFFFFFF);
textSize = a.getDimension(R.styleable.MyView_textSize, 36);