I want make background window blur when showing alert dialog.
I have tried -
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount = 0.0f;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
but it is not working in, also it seems "FLAG_BLUR_BEHIND" is deprecated.
is there any other way to achieve this without using third party libraries?
Related
When I set a dialog in full screen it isn't really fullscreen.
see here
How can I fix that?
Window window = getWindow();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
This code is in a custom dialog class that extends Dialog.
That's why I am able to write only getWindow().
Actually I don't need it to be fullscreen but I need atleast the pixel difference between the screen and the dialog box.
you can add the following theme to dialog's second parameter android.R.style.Theme_Black_NoTitleBar_Fullscreen
Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen)
I have a full screen app that has buttons that want to have a custom drop down when they are clicked. I was thinking of having a custom dialog show up that will have the options. Is there a way to tell the dialog where to show up?
If you want to create a Dialog window you can change the position of the screen in which it will be displayed by doing something like this:
//Dialog reference
Dialog dialog;
//Instantiate here your dialog
dialog = ... ;
//Get window layout parameters reference
Window window = dialog.getWindow();
WindowManager.LayoutParams windowLayoutParams = window.getAttributes();
//Set the parameters you want
windowLayoutParams.gravity = Gravity.CENTER; //e.g. dialog's will be centered
window.setAttributes(windowLayoutParams);
You can instead use Gravity.BOTTOM or Gravity.TOP to display the dialog accordingly. Alternatively, for more specific positioning you can try setting attributes "windowLayoutParams.x" & "windowLayoutParams.y".
I have created an AlertDialog with custom view that displays a SeekBar. Styling the seekbar etc. is not a problem, but I'd like to know how I could make the theme of my AlertDialog mimic the Dialog that appears when changing phone's sound volume. I mean both the position on the screen (about 1/5th from the top) as well as the width (almost match parent).
For clarification a screenshot I found on the internet of the volume controls:
http://triggertrap.com/wp-content/uploads/2013/09/media_volume.png
I found out that I can move the dialog using method described in this post:
https://stackoverflow.com/a/6050911
AlertDialog dialog = builder.create();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = 100; //x position
wmlp.y = 100; //y position
dialog.show();
It's still not the exact same length, but I guess without some global attribute or style to use, this would be difficult to mimic, as on tablets not only is the dialog specific length, it also has settings button to change volume of notifications and media.
I couldn't find such global style, I looked in Android source and even though I found VolumePreference class that seems to be close to what I'm trying to achieve, it didn't have any specific theme associated with it.
I wanted to know if it is possible to anchor a Dialog to a View in Android, or in general: just to display the dialog at a certain location on the screen.
P.S.
I don't want to use a PopupMenu because it is my understanding that one cannot customize the items displayed in the menu-- I'm ultimately trying to have text and put an image next to it to alert the user that they have a message or something new to see here.
Thanks for your time-
Use Window params.
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.copyFrom(getDialog().getWindow().getAttributes());
params.gravity = Gravity.BOTTOM;
params.y = YOUR_ANCHOR_VIEW.getHeight();
getDialog().getWindow().setAttributes(params);
I used Gravity.BOTTOM and view height to anchor dialog on top of anchor view.
Gravity.TOP will make y to apply from top and vise versa.
I used this code on onActivityCreated().
I use a popupwindow for displaying options in Android. I tried to dim/blur the activity when a popupwindow is active, but I did not find a solution... can anybody help me.
I used the following code but it does not work for me.
getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Use it like this:
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount=0.0f;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);