java - How to associate differentes view states with differents drawable items in runtimes -


how put 2 drawable item, 1 associate click view other state not clicked!! in code java !! because in program , create dynamically new views, 1 of them have different color in default state (when android:state_pressed="false").

exactly this: in java code:

<selector xmlns:android="http://schemas.android.com/apk/res/android">      <!-- pressed --> <item android:state_pressed="true">      <shape android:shape="rectangle">            <stroke android:color="#286dcc" android:width="2dp"/>            <corners android:bottomleftradius="5dp" android:bottomrightradius="10dp" android:topleftradius="10dp" android:toprightradius="10dp" />                  <!--  gradient bg listrow -->            <gradient  android:startcolor="#f1f1f2" android:centercolor="#e7e7e8"                        android:endcolor="#cfcfcf" android:angle="270" />      </shape>  </item>          <!-- default --> <item >      <shape android:shape="rectangle" >            <corners android:bottomleftradius="10dp" android:bottomrightradius="10dp"                     android:topleftradius="10dp"  android:toprightradius="10dp" />                 <!--  gradient bg listrow -->            <gradient  **android:startcolor="#f75522" android:centercolor="#f75522"**                     **android:endcolor="#f75522"** android:angle="270" />      </shape> </item>  </selector> 

i tried modifie that:

drawable shape = getresources(). getdrawable(r.drawable.bg_defaults); 

by don't know how attain android:startcolor,centercolor,endcolor change dynamically.

thinks all.

set onclicklistener button , in onclick change background of button

public void onclick(view v) {    if(v == buttonname) {      buttonname.setimageresource(r.drawable.imagename);    } } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -