A.Huseein February 2016

set image button background dynamically

I have defined array of ImageButton dynamically and that will take its buttons background from the user selected photos, my problem is that when I restart the app, the image buttons does not stay, how can I make it stay "along with the user selected background for it" without define it in the XML? I think of shared preferences but I am not sure if it will solve the problem!

icon[count]= new ImageButton(this);
icon[count].setImageResource(R.drawable.p1);
icon[count].setImageBitmap(photo);

Answers


Amit Vaghela February 2016

To save Background color you have applied , Shared preferences is perfect solution.

You need to save state of background color and retrieve it when you are restarting app(onRestart()) or onPause() or onResume().

how can I make it stay "along with the user selected background for it" without define it in the XML?

Using Shared preferences

Checkout Android Shared preferences example

Post Status

Asked in February 2016
Viewed 3,833 times
Voted 8
Answered 1 times

Search




Leave an answer