赞
踩
转载是一种美德 http://hi.baidu.com/545057627/blog/item/bd154f0bfef4e5181c9583d6.html
package com.cloud.test;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.RadioButton;
public class MyRadioButton extends RadioButton{
public MyRadioButton(Context context) {
super(context);
}
public MyRadioButton(Context context,AttributeSet attrs) {
super(context,attrs);
}
@Override
public boolean isChecked() {
return super.isChecked();
}
@Override
public void setButtonDrawable(int resid) {
super.setButtonDrawable(resid);
}
@Override
protected void onDraw(Canvas canvas) {
if(isChecked()){
super.setButtonDrawable(R.drawable.circle_green); //为选中RadioButton的图片
}else{
super.setButtonDrawable(R.drawable.circle_grey); //未选中RadioButton的图片
}
super.onDraw(canvas);
}
}
package com.cloud.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
public class RadioButtonTestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layout=(LinearLayout)findViewById(R.id.layout);
RadioGroup rg=new RadioGroup(this);
MyRadioButton mBtn=new MyRadioButton(getApplicationContext());
mBtn.setWidth(100);
mBtn.setText("RadioBtnOne");
mBtn.setHeight(60);
MyRadioButton mBtn2=new MyRadioButton(getApplicationContext());
mBtn2.setWidth(100);
mBtn2.setText("RadioBtnTwo");
mBtn2.setHeight(60);
rg.addView(mBtn);
rg.addView(mBtn2);
layout.addView(rg);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。