CheckBox類擴展了CompoundButton,但沒有添加任何內容。但有些如何獲得它的相應外觀。我在Android源代碼中發現了一些聲明,但不知道它們如何映射到CheckBox類?CheckBox如何獲取相應的drawables?
public class CheckBox extends CompoundButton {
public CheckBox(Context context) {
this(context, null);
}
public CheckBox(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.checkboxStyle);
}
public CheckBox(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
}
樣式
<style name="Theme">
<item name="checkboxStyle">@android:style/Widget.CompoundButton.CheckBox</item>
</style>
<style name="Widget.CompoundButton.CheckBox">
<item name="android:background">@android:drawable/btn_check_label_background</item>
<item name="android:button">@android:drawable/btn_check</item>
</style>
編輯:
也許我並不清楚......我明白瞭如何繪製分配給Widget.CompoundButton.CheckBox風格,但這種風格如何分配到CheckBox類?我在樣式名稱中看到了「.CheckBox」,但是這個命名約定究竟是什麼原因?如果是這樣,規則是什麼?如果我從CompoundButton派生MyCheckBox,我可以只定義Widget.CompoundButton.MyCheckBox樣式,它會工作嗎?
哦..的確,我忽略了checkboxStyle。 TY! – alex2k8 2011-01-11 22:57:16