How To set the BackGround Image for whole application android? - android

How to set the back ground image for whole application?I have achieved this but in some cases it throwing the Application background as black in some screens.

The thing you see on your screen is not an "application", but a contentView. this is made up from several things that can come from an XML file, and from code.
In the end you have several things on your screen that are Views. (for instance: linearView with textViews, etc).
Depending on what you have on your screen, you should do somehting to them. It is impossible to say what to do for all cases, as it differs. But in the end you should make sure that the background image is set for the 'big' View, and the views that are on top do not overlay it with something else.

You could set background for entire app activity window using
getWindow().setBackgroundDrawable(Drawable drawable)
//or
getWindow().setBackgroundDrawableResource(int resid)
but of course preferable to set background for root group of activity ContentView

Related

Ignore windowSoftInputMode for certain elements eg. Background Image

My question is, is there a way to get a certain view element to ignore the windowSoftInput setting, or to set a specific setting for one view element? (Any other solutions to my problem are also welcome)
Below are more details about my problem.
I have an Android activity with a background image set to the main FrameLayout. This layout contains a few other layouts, among others a brand logo on one side, and a scrollview with edittext boxes on the other side.
Using the windowSoftInput="adjustResize" works pretty well, but it distorts the background image. Using windowSoftInput="adjustPan" however pans the brand logo out of the screen and messes with the scrollview, and the keyboard blocks the edittext boxes.
So far, looking around the web and the docs I can't find a solution, or if this is even possible. Android layouts always seem to confuse me though..

Button invisble but enabled

i designed my whole activity page in photoshop and opened it in eclipse.I want to put buttons on my fake image buttons. Doesnt it make any problem? I use the code below to make the button invisible but it disables button too. How can i fix this problem?
android:visibility="invisible"
You should not do like that (having a fake ImageButton on a View you want to make clickable), as many error can occur with doing it. Assuming you are trying to put this button on a whole ImageView, or a whole Layout, or at least a whole view, you should consider adding a click listener to this view. Try to find more information about how to use the View.setOnClickListener(View.OnClickListener) method. You will have less error to debug with it.
But if you still want to do, try instead using android:alpha property:
android:alpha="0"
It will make the button become invisible, but still present, and still active
This android:alpha attribute allows you to specify an opacity value for a color.
To be honest you shouldn't be doing that unless you are testing something or prototyping. Instead, you should cut your design in photoshop and export the images for your buttons.
Your approch will most likely cause the buttons to be positioned incorrectly above the image when run on different devices with different screen sizes.
The correct way to do this would be to use the ImageButton view with a StateListDrawable set as the source image.
You can read more about State Lists here:
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
It's very easy to declare it in XML and have different images for various button states (pressed, disabled, focused, ...).
To sum it all up. I would do the following things:
Export images for my buttons in all the different states that you prepared (i find neutral and pressed as an absolute minimum).
Import them as drawables in your project (be sure to generate different versions for every screen density you want to support).
Create a State List Drawable XML Resource as described here.
Set the resource created in step 3 as the android:src property of your ImageButton (setImageResource(int)).
Try android:background="#null" for your button. It will make that default gray background disappear, making your button invisible but still allowing you to add text etc if you want to.
That being said: I would not recomment a button here. I would prefer Pauls answer in your particular case.

Easier alternative for showing Button as pressed or not than Selector?

I have an application with a large number of buttons across the various screens. Each of the buttons has a background image as well as text (so ImageButton is no good). I am aware that it's possible to have multiple versions of an image for the different states a button can be in (e.g. pressed and not pressed), that it's possible to put the different versions of the image in a selector, and then to set the background of the button to be the selector. However, this means I need to create two versions of each image (times four for each of the different densities I'm considering) and thus bloating the size of my apk as well as adding considerable time to produce the duplicate images.
Is this the only way to change the look of a button for when it's pressed or not (i.e. to set its background to be a selector which links to two different images), or is there some other easier way to change the look of a button, like specifying some built-in property of the button (its 'darkness' for example)?
Found one way of showing a View as pressed or not by wrapping the View in a FrameLayout, giving the FrameLayout a foreground drawable which is a selector consisting of a black-ish transparent colour (pressed state) and fully transparent colour (default state), and then setting the click listener on the FrameLayout instead of the View. Wrote it out in greater detail on my Blog here:
http://adilatwork.blogspot.co.uk/2012/12/android-show-view-as-pressed-without.html

android custom button

I need to create some custom buttons as shown in the image below
what is the best approach to follow?
thanks
Abdul Khaliq
That's a hard one. I made a lot of custom views, and the first thing I would thinking of is, made one Button with that above image, and handle onTouch by yourself so you can distinguish which area the user hit. There you can also change the state of the button, like changing the image to a bevel one e.g. when the left button is hit.
Can you imagine this ansatz?
You can place two transparent "invisible" buttons over the top of a background in a LinearView. Like two ImageButtons with a transparent png inside.
It is also possible to make this background animated when buttons are clicked using android animation class.

Positioning elements outside an Activity on Android

Is there a way to absolutely position an UI element on Android so that it is located outside an Activity? For example: can you create a fullscreen ImageView simply by moving/resizing an ImageView inside an existing regular Activity instead of creating a new fullscreen activity?
EDIT: Re-reading my question I see I wasn't very clear about what I'm trying to accomplish. I'd like to temporarily extend an element to cover the notification bar at the top of the screen. I need to create a semitranslucent fullscreen overlay but since translucent activities cannot cover the notification bar I'm trying to find out if it's possible for an element to break out of activity's bounds and resize itself to fill the whole screen, top to bottom.
That depends on what specifically you're trying to do. You can easily draw graphics offscreen and then animate their movement into the screen using a Canvas, but this is more for graphics than for user-interface elements. For moving buttons or such, you can have a look at another question here "How to position View off-screen". I gave a brief intro on how to use canvases, but the questioner found another way to do it using a customised linear layout and view animations.
Lastly, if you're trying to zoom and scroll an image around that's larger than the ImageView, there are some sources you can look at for inspiration. I realies this isn't strictly your question, but I'm including it since it might be linked to what you're thinking about. You can find a tutorial on Anddev.org and an open source app on Google Code.

Categories

Resources