读书人

更新button下的数字

发布时间: 2012-08-28 12:37:01 作者: rapoo

更新button上的数字

public class CounterButton extends Button{? ? ? ? protected int count=0;? ? ? ? protected final Paint myTextPaint = new Paint();? ? ? ? protected final Paint myCirclePaint = new Paint();? ? ? ? public CounterButton(Context context, AttributeSet attrs) {? ? ? ? ? ? super(context, attrs);? ? ? ? ? ? this.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.ic_dialog_email));? ? ? ? ? ? this.myCirclePaint.setARGB(150, 255, 0, 0);? ? ? ? ? ? this.myTextPaint.setARGB(150, 255, 255, 255);? ? ? ? }? ? ? ? @Override? ? ? ? protected void onDraw(Canvas canvas) {? ? ? ? ? ? ? ? ? ? if(count!=0){? ? ? ? ? ? canvas.drawCircle((float) (this.getWidth()*.75), (float) (this.getHeight()*.4), this.getHeight()/5, myCirclePaint);? ? ? ? ? ? canvas.drawText(Integer.toString(count), (float) (this.getWidth()*.75), (float) (this.getHeight()*.4), this.myTextPaint);? ? ? ? ? ? ?}? ? ? ? }? ? }
CounterButton cb=(CounterButton) findViewById(R.id.whateverYouGaveItInXML);cb.count=SomeNewNumber;cb.invalidate;

读书人网 >移动开发

热点推荐