I have u开发者_运维问答sed a selector file for ImageButton
but the image which I have defined onPress
is shown for only a very short period of time. I want that it will be visible until the next window opens.
Code:
<?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/bedpres_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/bedpres_pressed" /> <!-- focused -->
<item android:drawable="@drawable/bedpres" /> <!-- default -->
</selector>
You need to use ToggleButton in that case with the selector you have.
Button is considered pressed only between the ACTION_DOWN
and ACTION_UP
touch event actions, so if you want your button to change picture after it's been touched, you should make it manually, calling button.setBackgroundResource(R.drawable.bedpres_pressed);
Hope this helps.
After Button Cliked i think you wrote in xml file for only click so if you want your button to change picture after it's been touched, you try to change manually, calling button.setBackgroundResource(R.drawable.bedpres_pressed);
other wise try to use Toggle Button class
hope this helps.
精彩评论