help
help

Reputation: 851

how to make imagebutton in android stay highlighted?

if you click on a button in android, then it become orange, how would you make it stay like that in java? I tried setBackgroundcolor, but it change the shape of my button to the default shape when i use it and i dont want that.

Upvotes: 0

Views: 210

Answers (1)

Tofeeq Ahmad
Tofeeq Ahmad

Reputation: 11975

It not Possible for button as it does not have permanent focus but you can take one radio button and use android:button="@drawable/yourselector". In Radio button you will get checked event and Radio Button checked is permanent state

Make a layout in res/draw able

<?xml version="1.0" encoding="utf-8" ?> 
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:state_checked="false" 
             android:state_pressed="true"   
             android:drawable="@drawable/btn_attending_h" /> <!--clicked-->
       <item android:drawable="@drawable/btn_attending"/> <!--not clicked-->
 </selector> 

Upvotes: 1

Related Questions