系列ImageButton突出显示

时间:2015-07-15 15:29:47

标签: android xml xamarin

我有像redo, undo, choose, delete这样的一系列图像。我需要了解如何在用户点击redo时实施,并且会突出显示。当用户点击undo时,redo按钮将返回默认状态并突出显示撤消按钮。

我对redo按钮

有以下实现
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
      android:state_enabled="false"
      android:drawable="@drawable/redo_off" />
  <item
      android:state_pressed="true"
      android:state_enabled="true"
      android:drawable="@drawable/redo_on" />
  <item
      android:state_focused="true"
      android:state_enabled="true"
      android:drawable="@drawable/redo_on" />
  <item
      android:state_enabled="true"
      android:drawable="@drawable/redo_off" />
</selector>

2 个答案:

答案 0 :(得分:1)

您可能必须在各自的单击侦听器中设置所需的状态。不确定是否可以通过selector xml文件完成此操作。

答案 1 :(得分:0)

这就是诀窍 make方法切换并传递int值,如下所示

private void toggleButton(int value){
switch(value){
case 1:
//set enabled background color of the redo button
//set disabled background color of the undo button
//set disabled background color of the choose button
//set disabled background color of the delete button
break;
case 2:
//set disabled background color of the redo button
//set enabled background color of the undo button
//set disabled background color of the choose button
//set disabled background color of the delete button
break;
case 3:
//set disabled background color of the redo button
//set disabled background color of the undo button
//set enabled background color of the choose button
//set disabled background color of the delete button
break;
case 4:
//set disabled background color of the redo button
//set disabled background color of the undo button
//set disabled background color of the choose button
//set enabled background color of the delete button
break;
}
}

onYour按钮单击添加调用此方法 如果你点击重做按钮调用

toggleButton(1);

如果您点击撤消按钮调用

toggleButton(2);

如果您点击选择按钮电话

toggleButton(3);

如果您点击删除按钮调用

toggleButton(4);