码迷,mamicode.com
首页 > 其他好文 > 详细

自定义组件

时间:2014-05-22 01:59:09      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   class   c   code   

bubuko.com,布布扣
package com.example.ceshi;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class MyViwe extends View implements OnClickListener{
    private Paint _paintPaint;
    private int count;

    public MyViwe(Context context, AttributeSet attrs) {
        super(context, attrs);
        _paintPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        count = 0;
        setOnClickListener( this);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(count<5){
            _paintPaint.setColor(Color.BLUE);
        }else if(count<10){
            _paintPaint.setColor(Color.GRAY);
        }else if(count<15){
            _paintPaint.setColor(Color.YELLOW);
        }else{
            _paintPaint.setColor(Color.CYAN);
            Toast.makeText(getContext(), "呵呵", 1).show();
        }

        canvas.drawRect(0, 0, getWidth(), getHeight(), _paintPaint);
        _paintPaint.setTextSize(20);
        _paintPaint.setColor(Color.RED);
        String string = "你好!李浩"+ count;
        canvas.drawText(string,  0, getHeight()/2, _paintPaint);
        
        
    }

    @Override
    public void onClick(View v) {
        count++;
        //重新加载
        invalidate();
    }
    

}
bubuko.com,布布扣

 

自定义组件,布布扣,bubuko.com

自定义组件

标签:android   style   blog   class   c   code   

原文地址:http://www.cnblogs.com/lihaolihao/p/3738716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!