【发布时间】:2012-06-17 20:48:33
【问题描述】:
我有一些 CheckBoxPreferences,我可以通过如下所示的 xml 和 here 更改它们的图标,但由于用户有其他方式触发复选框的操作,而不是直接单击它(即可能在另一个活动中或甚至是另一个应用程序)我希望能够根据与操作一起发生的值更改以编程方式设置图标。例如,如果蓝牙打开,我希望图标是一个图像,而当蓝牙关闭时,我希望它是另一个图像。是否可以以编程方式更改此图像?
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/check_box_icon"
android:clickable="true"
android:focusable="false"
android:/>
【问题讨论】:
-
不确定是什么问题。更改图像只需使用 chk = (CheckBox) findViewById(android.R.id.checkbox);和 chk .setBackgroundResource(
); ? -
好吧,以上只是我通过将 android:widgetLayout="@layout/custom_checkbox" 添加到他们的 xml 属性中使用的 CheckBoxPreferences(不是视图)的 xml 布局。我需要通过代码更改这些复选框首选项的复选框图像...
标签: android image checkbox icons checkboxpreference