Markus
Markus

Reputation: 727

Making a button look pressed in

I'm using Eclipse to write the android application. I've added some standard buttons from the Form Widgets tab and successfully got them opening new windows which display additional buttons.

I would like the button that was pressed, to change appearance and continue to look pressed in after it is selected.

Upvotes: 2

Views: 4951

Answers (3)

Lukap
Lukap

Reputation: 31963

Use ImageButton and change the background of the button. you can use this kind of images depends of you need. Like this https://web.archive.org/web/20160429124711/http://www.devahead.com/blog/2011/08/creating-a-custom-android-button-with-a-resizable-skin/

Upvotes: 0

RajaReddy PolamReddy
RajaReddy PolamReddy

Reputation: 22493

create xml file using the button image like this

 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item 
      android:state_pressed="true" 
      android:drawable="@color/transparent" />
   <item 
      android:drawable="@drawable/closebutton" />
 </selector>

add the color folder in values

 <?xml version="1.0" encoding="utf-8"?>
 <resources>    
    <color name="transparent">#00000000</color>  
 </resources>

Upvotes: 3

jazz
jazz

Reputation: 1216

can use selector

 <?xml version="1.0" encoding="utf-8"?>
    <selector
      xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:state_focused="true" 
              android:state_pressed="false" 
              android:drawable="@drawable/button_settings" />
        <item android:state_focused="true" 
              android:state_pressed="true"
              android:drawable="@drawable/button_settings" />
        <item android:state_focused="false" 
              android:state_pressed="true"
          android:drawable="@drawable/button_settings_selected" />
        <item android:drawable="@drawable/button_settings" />
    </selector>

now set this drawable on background property of button in XML, now in coding take a boolean flag when button is pressed set the flag and set the bacground of the button(selected image) and on again click reset flag value and change the imageBackground to the selector again, thats it!!!

Upvotes: 1

Related Questions