How to Change color of Button in Android when Clicked? -


i working on android application. want have 4 buttons placed horizontally @ bottom of screen. in these 4 buttons 2 buttons having images on them. border of buttons should black color , border should thin possible. when click button, want background of button should changed blue color without color of border changed , should remained in color time. how can achieve scenario in android?

one approach create xml file in drawable, called whatever.xml:

<?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="true"         android:drawable="@drawable/bgalt" />      <item         android:state_focused="false"         android:state_pressed="true"         android:drawable="@drawable/bgalt" />      <item android:drawable="@drawable/bgnorm" /> </selector> 

bgalt , bgnormare png images in drawable.

if create buttons programatically in activity, can set background with:

final button b = new button (myclass.this); b.setbackgrounddrawable(getresources().getdrawable(r.drawable.whatever)); 

if set buttons' style xml, like:

<button   android:id="@+id/mybutton"   android:background="@drawable/watever" /> 

and link tutorial. hope helps.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -