我创建了一个自定义弹出视图,可用于设置优先级。最初,当我尝试设置显示弹出窗口时,我将ImageView
预设为ImageView.pressed(true)
,这由图像的灰色背景显示。
现在当我点击另一张图片时,我可以注册点击但无法在屏幕上显示更改,即无法在按下的图像上模拟ImageView.Pressed(true)
状态。
答案 0 :(得分:0)
出于同样的目的,我使用ImageButton
s,并且有一种方法可以为从onClick()
侦听器调用的一组相关按钮设置状态。例如,
private void configurePaletteStrokeWidth(Crayon.StrokeWidth strokeWidth) {
findViewById(R.id.iButtonStrokeWidthSmall).setSelected(false);
findViewById(R.id.iButtonStrokeWidthMedium).setSelected(false);
findViewById(R.id.iButtonStrokeWidthLarge).setSelected(false);
findViewById(R.id.iButtonStrokeWidthXLarge).setSelected(false);
switch (strokeWidth) {
case SMALL:
findViewById(R.id.iButtonStrokeWidthSmall).setSelected(true);
break;
case LARGE:
findViewById(R.id.iButtonStrokeWidthLarge).setSelected(true);
break;
case XLARGE:
findViewById(R.id.iButtonStrokeWidthXLarge).setSelected(true);
break;
case MEDIUM:
findViewById(R.id.iButtonStrokeWidthMedium).setSelected(true);
break;
}
}
每个按钮的xml类似于:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_stroke_width_small_tap" android:state_pressed="true"/> <!-- pressed -->
<item android:drawable="@drawable/button_stroke_width_small_tap" android:state_selected="true"/> <!-- selected -->
<item android:drawable="@drawable/button_stroke_width_small_normal" android:state_focused="true"/> <!-- focused -->
<item android:drawable="@drawable/button_stroke_width_small_normal"/> <!-- default -->
</selector>