1.CheckBox
<CheckBox
android:id="@+id/chb_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/check_bg"
android:checked="true"
android:text="喜欢"
android:textColor="#dd0000"
android:textSize="14dp" />
mChbTest = (CheckBox) findViewById(R.id.chb_test);
mChbTest.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compondButton, boolean b) {
if (b) {
toast("mChbTest选中");
} else {
toast("mChbTest 没选中");
}
}
});
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_check_no" android:state_checked="false" />
<item android:drawable="@drawable/ic_check_yes" android:state_checked="true" />
</selector>
2.RadioGroup
final RadioGroup mRgTest = (RadioGroup) findViewById(R.id.rg_test);
mRgTest.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
RadioButton sb = (RadioButton) findViewById(mRgTest.getCheckedRadioButtonId());
toast("选中:" + sb.getText());
}
});
<RadioGroup
android:id="@+id/rg_test"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radio_man"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:id="@+id/radio_women"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
</RadioGroup>
3.RatingBar
<RatingBar
android:id="@+id/rate_bar"
style="@style/RateStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="false"//是否只是指示器
android:numStars="5"
android:rating="3"
android:stepSize="1" />
<style name="RateStyle" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/start</item>
<item name="android:minHeight">20dp</item>
<item name="android:maxHeight">20dp</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@android:id/background"
android:drawable="@drawable/ic_start_off" />
<item
android:id="@android:id/secondaryProgress"
android:drawable="@drawable/ic_start_on" />
<item
android:id="@android:id/progress"
android:drawable="@drawable/ic_start_on" />
</layer-list>
4.ProgressBar
// 圆形进度条
<ProgressBar
android:id="@+id/progress"
style="?android:progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
// 线形进度条
<ProgressBar
android:id="@+id/progress1"
style="?android:progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50" />
自定义样式
针对线形进度条
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<solid android:color="#dd0000" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape android:shape="rectangle">
<solid android:color="#00dd00" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape android:shape="rectangle">
<solid android:color="#0000dd" />
</shape>
</clip>
</item>
</layer-list>
<style name="lineProgressStyle" parent="@android:style/Widget.ProgressBar.Horizontal">
<item name="android:progressDrawable">@drawable/progress_horizontal1</item>
</style>
// 针对圆形
<style name="circleProgressStyle" parent="@android:style/Widget.ProgressBar.Large">
<item name="android:indeterminateDrawable">@drawable/progress_red</item>
<item name="android:minWidth">76dip</item>
<item name="android:maxWidth">76dip</item>
<item name="android:minHeight">76dip</item>
<item name="android:maxHeight">76dip</item>
</style>