Android - ImageButton上翻转的不同图像

los*_*sit 6 android imagebutton

当用户的焦点到达ImageButton时,是否可以指定不同的图像?我想在LinearLayout上显示图像按钮,并在用户的焦点出现在按钮上或用户按下按钮时更改图像.

谢谢.

Nat*_*ate 5

是的,你可以这样做.你需要的是一个定义选择器的drawable xml文件.

<selector xmlns:android...
  <item android:state_enabled="false" android:state_focused="true" android:drawable="..." />
  <item android:state_enabled="true" android:state_focused="false" android:drawable="..." />
</selector>

然后,在布局XML中指定ImageButton时,使用此可绘制XML的id.