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

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -