Change app background - java

I'm currently making an android app in which I'd like the user to be able to change the background image.
I've got 3 images and a screen where I can choose a picture and a button for applying.
The issue:
I can allow the user to see all images in the way I want, but I don't know how to set the selected image as app background.
What I want to do:
I want the user to click a button, which exports the selected image to "bakgrund.png" in "/res/drawable-mdpi" and replaces the current one. This would allow me to easily integrate the background switcher. Renaming of current files also works.
PS: My current background images are located in /res/drawable-mdpi named 1.png 2.png and 3.png.

Easiest way would be to call the setBackgroundResource(image_id) method on the root layout. Like if you have a LinearLayout which has android:id="#+linear" as the root layout in the layout xml, then this code will help:-
LinearLayout linearLayout=(LinearLayout) findViewById(R.id.linear);
linear.setBackgroundResource(R.drawable.1);//call this in the OnClickListener's OnClick Method

Firstly, you need different themes which has different backgrounds. So you may use this.setTheme method in your Activity.
Indeed I suggest you, two different layout (with different backgrounds but have same components) and using setContentView during onClick.
I hope it solves your issue.

Related

Transparency in Background Picture

I want to achive that I have a transparent background BUT with a picture !
So if got this in the XML file of my layout :
android:background="#drawable/wallpaperpic"
Now I want to transparent it so the background menu (f.ex. widgets or app menu) is seeable but also my drawable/wallpaperpic and the rest of my buttons etc are normal (100%).Hopefully I was able to express my self !
My Background : https://amazingpict.com/wp-content/uploads/2015/04/polygon-texture.jpg
I want to have this
WHERE you also can see my background picture a bit
Try to set the alpha property of the view, like:
yourView.serAlpha(10);
If, as I'm guessing now, you have two layouts, one within the other, where the parent layout has the background, you can do this in the child layout:
android:background="#null"
This way, you can see the background, and your elements are intact.
Option 1 is to convert your image to a PNG and add an alpha channel.
Option 2 (which I would recommend) is to have a separate view that acts as your background, and set the alpha property for this view only. You can use a FrameLayout to put this background view underneath your other controls.
In my opinion use TintableBackgroundView.
TintableBackgroundView.
If you launch your activity the normal way, the system will not render anything behind it (i.e. the launcher will be completely gone - it could even remove it from memory).
You'll need to implement your activity as an alert window. This answer has details on how to implement it.

New to Android, How can I edit my Relative Layout using Java?

I have defined my Relative Layout using the drag and drop tool in Eclipse, so all of my buttons are laid out how I wish. My issue is when I set the onClick listener, that calls a method in another class. So to be able to redraw items on screen, I need to access the layout manager so I can add and remove buttons from the screen as well as update textViews. I have done all of this in a demo I made in Java, and I used a JPanel with GridBagConstraints. Now that I am moving to Android, a system I haven't done much development in, I am at the point where I have to learn some new stuff. For example in my demo I made I could do this:
grid.remove(trueButton);
grid.add(falseButton);
grid.remove(textField);
grid.add(backButton);
Essentially I want to be able to do the same sort of thing in my Android app. If you guys need more info I can provide, I wasn't really sure how much would be needed since I am looking at really just where to start. Everything has been declared in the XML since the drag and drop part of Eclipse does that all for me. It is just the Java part that is giving me some issue.
Why not just setVisibility of the buttons you wish to hide/show? Same with the TextViews.
You can set visibility to 'GONE' and it will be as if the view has been removed (taking up no space in the layout and not responding to touch events.).

Android Setting Up Splash Screen(Activity) Like Iphone Part2

After getting solution to call my splash activity only one time (Part1 Question), Now i have to set up my splash activity.
On My First Layout i want functionality like this :
Image One <--> Image Two <--> Imgage Three --> Second xml(Activity)
Also on every image their will be a page control that will indicate on which image is currently on layout(Like the attached screenshot)/ or can be any other way to show this.
That Means From Image one i can go to image two on scrolling to right(I can come back to image one on scrolling to left) From Image two i can go to Image Three on scrolling right(I can come back to image 2 from Image three if i scroll to left)But if i scroll to right from Third Image then i should get to my Second Activity and never return back on those images.
i.e
I want to have scroll view having those three images with the page controller then after we scroll down to the third/last image on further scrolling to right i want that my second activity should be loaded and the splash should never come up.
Can any one tell me any idea how this can be done.
To make splash sheet with scroll view and page control & switch to second activity when done scrolling.
I don't want animation i want it to work manually like scrolling/ or any other way to implement this.
Coding will be much appreciated.
To implement scrollable images like shown above use ViewPagerIndicator library given HERE. Its simple to integrate and will take few minutes. All you have to do is read the usage section in given link.
For switching activity on last page, simply implement onPageChangeListener described in link and check for page number.

Android - How to display another overlay in onTap action of another overlay

I am using MapView to display some polygons (zones) as Overlays on the canvas. I extended the class Overlay and now would like to implement the onTap method. After user taps on one of these zones another overlay should be displayed. I would like to define the layout of this overlay as a normal XML layout and than just inflate it and display.
I have already looked on one example called android-mapviewballoons, but it uses itemized overlays which take an Drawable resource and display it on the mapview. This drawable can than be taped. In my case I want my zone (polygon) to be the clickable resource. Can anyone help me please?
Step #1: Implement onTap() in your Overlay and confirm you are getting control when you want to.
Step #2: Adjust your existing layout such that the MapView is in a container that supports Z-axis ordering, like a RelativeLayout
Step #3: In onTap(), add another child to the container (and, eventually, get rid of that child, when appropriate)
Here is a sample app from one of my books demonstrating this with an ItemizedOverlay, but there should be no significant difference for using the technique with a regular Overlay.

Android Dropdown Effect - Spinner or not?

Achieving a true "dropdown" effect (as seen in Adobe's Photoshop Mobile app for Android, image below) has proven challenging using Androids built-in methods.
As others on Stackoverflow have told me, editing the style of a dropdown list view of an Android spinner is limiting.
How is this dropdown effect done?
(I can't seem to get an image to show, so here's a link: Adobe Photoshop Mobile for Android
After viewing the Adobe slideshow I think the way I would attempt to get that to work, using the Android Java SDK, would be to create a ListView object with a transparent background, and then dynamically hide/show it in that position when the menu button is clicked by setting the View's visibility to VISIBLE or GONE.
Getting a ListView to be transparent shouldn't be that difficult. I'd look into AbsoluteLayout to get it to hover over everything in that spot.
Another option might be to display the ListView in a custom Dialog that you've written, again positioning it in that exact spot on the screen so that it looks like a menu extending from the button that was clicked.
It's probably done using low-level draw functions.

Categories

Resources