首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

更新button下的数字

2012-08-28 
更新button上的数字public class CounterButton extends Button{? ? ? ? protected int count0? ? ? ? p

更新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;

热点排行