I have multiple popups in my android app. I would like to control the "z-index" of the popups. I can't seem to find any way to control the relative positioning. Is this possible?
you basically cannot have z-index for your activities.
but whenever you want to bring any activity on the top, you can add the flag Intent.FLAG_ACTIVITY_REORDER_TO_FRONT to your Intent.
I've seen some peculiar things, like an alert dialog popping up behind my custom dialog. But after cleaning the project they behave properly (last called view is shown above/infront of the previous views)
Related
In an app I am working on, I'd like to have a bar with some controls always present at the bottom of the screen. It should overlay every activity in the app but also be able to disappear and reappear. To do this I've considered some options, such as simply using a linear layout and setting the visibility in every activity or using a fragment somehow. Probably those would work but I feel there must be a better solution. So my question is: what is the best way of doing this?
There are two ways you could do this. You could just use Fragments, and make your overlay be a fragment.
The other way would be to sublcass Activity with an AcitivityWithOverlay, which handles the overlay appearing and disappearing then have all of your activities inherit that. If I did it this way, I'd make my overlay a singleton so I wasn't creating extra versions all over the place that did the same thing.
I'm developing an app that includes reviews of items and due to my design, I want to only show all the reviews in a popup window like in Google Play Store:
What should I use to create that white panel that appears over the current window and contains the necessary information? This should be simple but I'm a newbie and I can't seem to figure out what this "widget" is. Please help me if you are familiar with this so I can use this cool design pattern. Thanks.
It seems you want to display a layout as a popup in another activity.
If you want to do this using an Activity instead of a Dialog, you can do this by setting the activity's theme to android:theme="#android:style/Theme.Dialog" in the manifest - this will make the activity appear like a dialog (floating on top of whatever was underneath it).
A better way to do it would be using a DialogFragment. You can display information in the form of a popup and it will have its own lifecycle. That will be much better than displaying an activity like a dialog
Ram kiran's answer is a good one and one which I like to give also. But just so you have another option to look at you can consider PopupWindow
As stated in the docs, it is
A popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.
I've used this and it works out nicely in some situations. It really depends on what your exact needs are as to which will work best for you.
I want to create a pop-up window (with black transparent background around it) that would appear above the application activity screen (by clicking on a button). This pop-up would contain a video player, a list of videos to be played and some other elements.
This pop-up has to be a fragment since I need to re-use it from other app fragments.
So my question is : what is the best way to achieve that? I personally see 2 options :
1) adding the pop-up as a fragment on the layout and to show + activate it whenever I need. But in that case, how can I put a black transparent background around it that would fill the whole screen?
2) using DialogFragment but it seems that this class is not very well-designed for this kind of stuff.
What do you think?
Thanks in advance.
DialogFragments are the suggested way to launch Dialog views from within a Fragment, so this is the solution I would suggest for you.
You can do pretty much anything you need within the DialogFragment. You will be in full control of the UI using this method.
Here is a SO discussion of the same point, with good info: Android DialogFragment vs Dialog
I am playing around with controlling the UI Navigation buttons in ICS.
The current mechanism for suppressing the Nav Buttons is to call setSystemUiVisibility from a View using the SYSTEM_UI_FLAG_HIDE_NAVIGATION or SYSTEM_UI_FLAG_LOW_PROFILE flags. This seems like a strange place for setting these flags, as most other related settings (such as hiding the status bar) have been done through window LayoutParams properties.
My question is if any of you have ideas for a good way to do it from an Activity context. Currently my app is designed to start with a base activity class which contains any functionality I want throughout my entire application. Specific Activities are then derived from that base class. I would like to be able to set the UI nav flags from that base Activity so I don't have to do it in multiple spots throughout my source code... but my base Activity does not contain any View objects.
As a secondary statement, what I would really like to be able to do is completely remove the NAV buttons (such as using SYSTEM_UI_FLAG_HIDE_NAVIGATION) and not have them come back on user input (giving my app complete control over the UI). I know this is not something that any app from the market should be able to do... but I am not developing something that will available via the market. My current plan involves a custom build of the OS that will allow me to accomplish this, but it would be nice if there was some method of eliminating those soft buttons in the meantime.
Thanks!
This is what I put in onCreate of my activities:
View main_layout = dialog.findViewById(android.R.id.content).getRootView();
main_layout.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
It's almost like calling it from an activity context. At least it's not dependent on having a view defined at compile time. I know STATUS_BAR_HIDDEN is deprecated, but I can't get SYSTEM_UI_FLAG_LOW_PROFILE to compile at the moment...
But +1 on the "this seems like a strange place for these settings". Should be something you can define in the manifest once for the entire app.
You can't completely remove the ICS navigation buttons.
You can hide them completely, but they'll reappear as soon as you touch the screen:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Unfortunately, some ICS UI layers like Samsung's TouchWiz won't recognize SYSTEM_UI_FLAG_HIDE_NAVIGATION.
Alternatively, you can minimize them and they'll only appear when the bar it tapped:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
You'll probably have to build your own ROM to eliminate them completely.
I have tried and tried to get a transparent, floating Activity to show up (as an overlay), but allow whatever is behind it to still show AND update. Right now it seems that if the Activity behind mine is closed or a new one opens (could be either in this case), the new underneath Activity does not shine through my Activity to the user.
I have tried every combination of Flags I can come up with, and at this point I'm assuming Flags are not the answer. Can anyone help me find the proper code to do such a thing?
Before anyone asks, I have a valid use case for this type of Activity; no, I don't plan to annoy the user with it.
As far as I know, this is not possible. It should be possible to create an activity using the theme Theme.Dialog or Theme.Translucent (see http://developer.android.com/guide/topics/ui/themes.html) to have whatever activity is beneath it still show at least partially. The problem is, is that the Activity below will be Paused (it's onPause will have fired, but it's onStop will not have) and I don't believe it is possible in any way to have it run any code.
I have not investigated in making a transparent Activity but I don't think it's possible in an Activity way. This seems to be logical since even if you have a transparent Activity it's still relying on the View inside it - the View makes the transparent part, not the Activity. This means you're probably gonna end up with a transparent View instead.
If you have a "front" Activity with a transparent View and then a "back" Activity, the "back" Activity would not be visible to the user - and that's because you're in another Activity.
So, the correct way is to use a transparent View.
It is possible to update the activity below by implementing a Broadcast receiver on it, and sending Broadcasts from whenever you want.