In my application, four activies are present (Add, view , search and settings). in settings activity, it will display 10 buttons ie. apply to set background image. images are saved in drawable folder. if i click on button image it should change the background of all activities
First of all you need to use SharedPreferences.
set value of selected background in SharedPreference and display images according to the value of it in all Activities
Related
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);
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
I've just about got the concept of using the Bundle instance state to store stuff that wouldn't otherwise be stored when an Activity is destroyed and recreated (e.g. on screen rotation). I also see that you don't need to do this for basic information for each View, like text in a TextView, because the system does that for you (at least for those Views that have an ID assigned). See http://developer.android.com/training/basics/activity-lifecycle/recreating.html.
But when I change the background color of a View programmatically (I'm using a basic View as a color swatch linked to a color picker) using setBackgroundColor(), I find that the color is lost when the screen rotates, and reverts back to the original setting. I do have an ID assigned to the View.
Should that color information be preserved automatically, or am I just being hopeful, and do I have to keep track of that separately and restore the color on recreation of the Activity?
Thanks.
Yes when you set your Background Color directly by View.setBackgroundColor() Always when the app is changed to landscape this is replace by the default layout. You should implement:
setContentView(R.layout."activitylayoutname");
And of course on the layout set a background parameters.
Edited 1:
Try this link to set background valĂșes:
Setting background colour of Android layout element.
And also if you want to preserve other valĂșes between Activities, just recreate an activity:
http://developer.android.com/training/basics/activity-lifecycle/recreating.html
i am new to custom PreferencesActivity, i am working since three days to get custom preferences, what i want is i want a preferences screen with background image and color views for every preference cell,
1) i had tried with res/xml/preferences.xml, but i cant create background image i had tried with many solutions but i couldn't find any solution.
2)i had tried with res/layout/pref.xml, but i couldn't able to save the settings of preferences
please help me in creating such type of preferencesActivity with background image
see How set background drawable programmatically in Android
and save this link http://developer.android.com/reference/android/content/SharedPreferences.html
What's a good way, both layout- and codewise, to accomplish the following:
Display one or more clickable images on the screen.
By default, the images are default images (duh)
When clicking on them, they change to a specified image
When clicking again, the change back to the default image
I cannot set all the images in the xml layout file(s), since I must be able to programatically set and change the images when clicking, and keep a record of the images on display etc.
In case anyone wonders: Yes, this is supposed to be a simple "memory" game, where I show x images, and click on two of them to display them, and give a result if they're identical.
I would suggest you to use ImageSwitcher, as the view, and setOnClickListener on the ImageSwitcher, to apply image changes on click action.
i m developing application in which i have to change the background image on different tab..
i m using linear layout to change background for different activity..i m getting output but..my background image is not fill parent ...i want to set background image in whole screen..do u have any idea how can i do that??
Check your device screen size and your background image size.
thank you buddy..
i found the answer...i declared Tab host object statically and on click of tab,different activity get called..and i changed the backgrond of tab host by code..and its work...