我有一个ToggleButton设置如下:
final ToggleButton filterButton = (ToggleButton) findViewById(R.id.filterTags);
filterButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (filterButton.isChecked()) {
// pop up the list of tags so the user can choose which to filter by
// once one is chosen, the spinner will be updated appropriately
showDialog(DIALOG_TAGS);
} else {
// going unpressed, set the the spinner list to everything
updateSpinner(db.itemNames());
}
}
});
Run Code Online (Sandbox Code Playgroud)
对话框如下所示:
case DIALOG_TAGS:
final String[] tagNames = db.tagNamesInUse();
dialog = new AlertDialog.Builder(this)
.setItems(tagNames, new DialogInterface.OnClickListener() {
public …Run Code Online (Sandbox Code Playgroud) 我尝试使用XML文件更改切换按钮的背景颜色为白色,但切换按钮完全损坏.看起来所有按钮都覆盖着白色.
将切换按钮的颜色更改为白色时,切换按钮上没有ON或OFF的指示.是否有另一种改变背景的方法,不会损坏切换按钮的指示?
<ToggleButton android:id="@+id/togglebutton"
android:layout_width="100px"
android:layout_height="46px"
android:background="#ffffff"
android:layout_above ="@+id/save"
android:textOn="DAY"
android:textOff="NIGHT" />
Run Code Online (Sandbox Code Playgroud)
这就是我的XML代码查找切换按钮的方式.