在android中自定义CheckedTextView

时间:2013-09-18 17:47:34

标签: android android-custom-view checkedtextview

我正在使用我工作中不属于我的代码。 此代码使用CheckedTextView,执行以下操作:

...
    AlertDialog.Builder alert;
        v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
        switch (soundPreference.getType()) {
        case BOOLEAN:
            CheckedTextView checkedTextView = (CheckedTextView) v;
            boolean checked = !checkedTextView.isChecked();
            ((CheckedTextView) v).setChecked(checked);
            switch (soundPreference.getKey()) {
            case SOUND_ACTIVE:

                sound.setAlarmActive(checked);
                break;
...

效果很好,问题是我想要更改复选框图形。 现在它看起来像(defualt,我认为): enter image description here

我希望得到这样的东西:

enter image description here

如果在xml中定义了CheckedTextView,则知道如何操作。 我的问题没有在xml中定义,不知道该怎么做。

我发现了这个: Customize the CheckedTextView for ListView 但我不知道如何实现它

感谢任何帮助。

非常感谢您提前

2 个答案:

答案 0 :(得分:5)

http://developer.android.com/reference/android/widget/CheckedTextView.html#setCheckMarkDrawable%28int%29

示例:

myCheckedTextView.setCheckMarkDrawable(R.drawable.icon);

此方法允许您动态设置复选标记图像。您应该在设置CheckedTextView时调用它。 开发人员参考中的方法只需要您要使用的图像资源的ID。

还有一个版本将Drawable作为参数而不是id。

答案 1 :(得分:0)

CustomCheckBox

您需要创建自定义list_item布局。

如需完整说明,请浏览以下链接......

http://amitandroid.blogspot.in/2013/09/android-custom-multiple-choice.html

希望这会对你有所帮助。