java - Drawable resource file - Changing Image -


long description:

so want resting image different depending on circumstances. user gains (in case) currency, want check see whether has enough purchase. if has enough want button change colors visually tell user has enough buy upgrade. every time currency value changes call upon function. though life not perfect can't combine java code in xml , have no clue how call upon it.

summary:

my question is how change @drawable/button through mainactivity

example of want happen:

afunction(){     if(whatever){             <item android:drawable="@drawable/buttonclick"    android:state_pressed="true"></item>             <item android:drawable="@drawable/button"></item>             }             else             <item android:drawable="@drawable/buttongray"></item> } 

in xml:

<item android:drawable="@drawable/button"></item> <item android:drawable="@drawable/buttonclick" android:state_pressed="true"></item> <item android:drawable="@drawable/buttongray" android:state_enabled="false"></item> 

and in java code:

if(whatever){     button.setenabled(true); } else {     button.setenabled(false); } 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -