我已设置此状态列表:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/hello_pressed"
/>
<item
android:drawable="@drawable/hello"
/>
</selector>
但是当我点击元素时,drawable不会保持“按下”状态。它变为“按下”,然后当我松开时,它会恢复到正常的可绘制状态。
按下元素后如何按住它?
答案 0 :(得分:0)
正确的方法是来自代码......
boolean isPressed = false;
//click event on your control
public void OnClick(View v) {
if (!isPressed)
yourControl.setBackgroundResource(R.drawable.hello_pressed);
else yourControl.setBackgroundResource(R.drawable.hello);
isPressed = !isPressed;
}