user830944
user830944

Reputation: 1

ImageButton onclick issue

I have used 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>

Upvotes: 0

Views: 192

Answers (3)

sravan
sravan

Reputation: 5333

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.

Upvotes: 0

Egor
Egor

Reputation: 40228

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.

Upvotes: 0

PravinCG
PravinCG

Reputation: 7708

You need to use ToggleButton in that case with the selector you have.

Upvotes: 2

Related Questions