Android AlertDialog: How to hide the activity behind it? - android

I'm looking for a way to hide the underlying activity of an AlertDialog.
I tried to set a solid overlay color but it looks like there are no default methods for doing this. Is there a way to do this without creating a new activity with a solid background color that then fires the dialog?
I couldn't find anything other than doing it by firing a whole new activity on StackOverFlow, google, the android documentation and the AlertDialog API page but this seems like overkill.
Ideally I'm looking for something like alert.setOverlayColor(int color)

Create a custom layout for the Dialog with height and width as "match_parent". Use the area required by dialog and put a solid background in the top level.

Related

Android Dialog curved edges

I have implemented a custom Dialog in android. The custom view contains curved edges but not the Dialog itself. I want this Dialog to get the shape of curved edges. How it can be done?
As you can see, the curved edges are not actually curve.
Any help or idea would be highly appreciated.
SOLUTION
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Thanks everyone.
Happy coding.
I guess there are two possible reasons that make your custom view like this:
You forget set the dialog's background transparent first;
The custom background image's corner part is not set transparent.(you can set it transparent and save it with png format.)
A dialog is a small window that prompts the user to make a decision or
enter additional information. A dialog does not fill the screen and is
normally used for modal events that require users to take an action
before they can proceed.
You need to create a custom dialog in Android.
Create a custom dialog layout (XML file).
Attach the layout to Dialog.
Please check below Demo Links
Android Custom Dialog Tutorial
How to create custom Dialog Box in android ?

Android dialog : Is there a way to make background android UI clickable while dialog is displayed?

Currently, I am using Libgdx for making app with lots of animation. I am trying to use android Dialog for showing paragraph with html tags through Interface. While, I can change dim color of background UI back to normal with following code.
paragraphDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Is there anything I can do to make background UI work? (Button click, textview focus etc)
And, I have tried GlyphLayout of Libgdx for paragraph. It frequently crashes & also doesn't support html tags. I am using dialogs, as it is pretty easy to use xml layout easily with dialogs. If there are any other options, Please suggest.
Thanks,
your dialog is blocking the entire screen, doesn't matter if the edges/background are somewhat transparent or not 100% alpha, it is still the view that is currently on top. therefor, you can't click on it directly.
i think the best way to achieve your goal is with a fragment. not a dialog.

How to create an overlay the shows a Progress Spinner that can go on top of all windows?

I come from iOS background where I can display new views stuff on top of everything easily. In android, it doesn't seem as straight forward because each Activity has a layout already defined. So, if I wanted to create a loading view (spinner in the middle), adding a new Layout inside the original layout would mess things up.
Is there any way to do this?
I also tried use a dialogFragment and customizing the dialog, but it always shows the space where a title of the dialog is shown. I'm not sure how to get rid of this, so there must be some universal way for apps to do this.
You can use shared preferences to flag a value true, and in each each Activity's onResume, you can check for that value. If that value is true, then you can start an activity in a new thread which has just a spinner and a transparent background.
I'm using the following workaround:
Use a FrameLayout as your main layout. Define your UI as the first child (or just not the top frame), then define your spinner in the top. When you want to hide the spinner, just setVisible(View.GONE).

Create blue "tutorial" dialogs as in Android 4.4

I would like to create some "dialogs" like those shown in Android 4.4 for example when you are first shown immersive mode. The little arrow is important for me because I would like to have the dialogin different places on the screen.
This is what I'm talking about:
Do I need to create a custom AlertDialog? How do I move it around, can I use the coordinates of a View? I don't really know where to start. Are there any examples on creating this type of thing? I am not interested in using the ShowcaseView library as in my opinion has the "old" holo look.
You can get the coordinate of views using getLocationOnScreen(), make sure to call this after the views have been inflated (so, not in onCreate() of your activity) or else you will be returned default int values (i.e. 0).
You should probably create your own DialogFragment. Incorporate your own custom layout which contains the little bubble and the button. A Quick and dirty sample for the onCreateDialog() would have the following
Dialog dialog = new Dialog(getActivity());
// Get rid of the annoying alert dialog title bar
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// You must set the content view after requesting window features, not before.
dialog.setContentView(someView);
// Make the dialog full screen
dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
//Dim the background
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.argb(80, 0, 0, 0));
To incorporate the little arrow, you can try having variations of 9-patch images as the background of the little bubble. Another alternative would be to have an arrowhead and a bubble put into the same container, and setting the margin/padding between them to 0. Since you have the coordinates you can adjust the horizontal margins of the arrowhead accordingly. This is actually a pretty cool idea, I think I'll try my own interpretation of it this weekend.
I have actually been working on my own interpretation of the showcase library, Here is what i achieved. Much of the dynamic position changing should be the same I would think

How to make the ambience of a Dialog transparent

I want to use a Dialog for the pause screen of my game. But the dialog always shades the subjacent Activity (the ambience around the dialog). How can I avoid this effect?
Afaik Dialogs in Android have that default behavior and it cannot be changed. For your requirement you should use something like a PopupWindow. This and this are the links to tutorials that can help you get started.

Categories

Resources