Dim or Blur background in activity - android

In one of my project I used PopupWindow. My problem is while viewing popupwindow the design seems to be uncomfortable to work. So I want to dim or blur my activity background. I searched a lot, but most of the answers seems only for Dialog not for PopupWindow. Is it possible in android to dim our activity background while viewing PopupWindaow.

I solved this problem by setting the background to the layout of the pop-up window with the following.
android:background="#80FFFFFF"
Thnaks..And it works as expected.

you can simply use this :
ColorDrawable dw = new ColorDrawable(0xb0000000);
dialog.getWindow().setBackgroundDrawable(dw);

There is always a work around. Before showing your PopupWindow use another PopupWindow which has nothing but a dark translucent tint. Also when dismissing dismiss both pop up windows in the reverse sequence.
For code see this

Yes, it is possible, try android:theme="#android:style/Theme.Translucent" , it will make your activity transparent.

Try this
Window window = popUpView.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.CENTER_VERTICAL;
wlp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
wlp.dimAmount = (float) 1.0;
window.setAttributes(wlp);

Related

Android 11 UI issues with dialog transparency

did you notice any UI issues with Android OS 11(API 30).
I have a full screen transparent dialog with a progressbar at center, it is working till Android 10, don't know its showing a black dark background in Android 11. Please share if you guys have any thoughts on this issue.
This is how I am setting dialog background transparent:
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Well, setBackgroundDrawable() is deprecated now that's probably why you are getting this issue. An alternative could be setBackgroundResource(R.drawable.your_drawable) where you can replace the drawable with your color.
Struggling with same issue lead me to this solution;
Window window = dialog.getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.argb(58, 0, 0, 0)));
dialog.requestWindowFeature(1);
dialog.setContentView(R.layout.dialog_layout);//Set contentView after setting background drawable
dialog.show();
Simple, setting the contentView after setting background drawable solved the issue. There might some other approaches like setting background as resource. This is what fit for me.
Without further details I can only make a guess on the solution. But I believe this is an issue where LayoutParams are being replaced. Instead I would suggest modifying the LayoutParams a view/window already have.
Get the layout params:
WindowManager.LayoutParams params = window.attributes;
Modify attributes as you like, e.g. params.width = WRAP_CONTENT And then set the modified layout params:
window.attributes = params
I suggest this solution to all LayoutParams, it usually give the best solution to more android versions. And less attributes has to be set.

how to make background of dialog back

I would like to solve the problem I've got. I made a dialog above a activity of android, but I would like to make the background black(opaque). All the guide shows only how to make it transparent. How can I make it opaque?
Yes, it is. You can control it.
After creating dialog:
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount=0.0f; // Dim level. 0.0 - no dim, 1.0 - completely opaque
dialog.getWindow().setAttributes(lp);
Upd: you can even add blur behind the dialog:
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Hello If i understand your question correctly then you can do it by below code :
Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
mDialog.getWindow().setBackgroundDrawable(d);
Use this line :
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(0xff000000));
hope it helps :)

Disable background dim on ProgressDialog/AlertDialog in Android

I use an AsyncTask with a ProgressDialog in it.
This automatically causes a background dim of about 40%. I want to turn this dim off (0% dim), but what I tried, didn't work:
myLoadingDialog = new ProgressDialog(MainActivity.this.getApplicationContext());
myLoadingDialog.setMessage("Loading...");
myLoadingDialog.setIndeterminate(true);
myLoadingDialog.setCancelable(false);
WindowManager.LayoutParams lp = myLoadingDialog.getWindow().getAttributes();
lp.dimAmount = 0.0f;
myLoadingDialog.show();
The problem with that dim was, that I had to terminate my Tablet's SystemUI-Process to achieve a Kiosk mode (with no System-Bar) and the ProgressDialog dims everything but the area where the System-Bar was, so I have a bright border at the bottom of the screen.
If there is a way to get a complete fullscreen-dim, I would be also happy.
Thanks for any help
use
myLoadingDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHI‌​ND);
you can add this theme to solve this problem also
<item name="android:backgroundDimEnabled">false</item>
You can also change the relative amount of dimming with the following:
window?.setDimAmount(0.2f)
This is set in onCreate of your dialog class.

AlertDialog is not rendering correctly

As you can see in the screenshot, my alert dialog border is not rendering correctly. It is placing a black background behind the dialog. This only happens when I resize the dialog. I'm new to android/monodroid so I don't really even know where to start looking for a cure. You can see that the toast message renders the border properly (with a semi-transparent border).
Any thoughts on how I can get rid of the black background behind the dialog border ?
resizing code:
Dialog dialog = db.Create();
WindowManagerLayoutParams p = new WindowManagerLayoutParams();
p.CopyFrom(dialog.Window.Attributes);
p.Width = 900;
p.Height = WindowManagerLayoutParams.WrapContent;
dialog.Show();
dialog.Window.Attributes = p;
I would advice to use the DialogFragment instead of the older dialog, at work we have had quite a few problems with the older dialogs.
http://developer.android.com/reference/android/app/DialogFragment.html
And this problem in specific on a few devices.

Size of Alert Dialog or Custom Alert Dialog

I am creating my application for all tablets of 10.1 and now i am trying this on samsung galaxy tab.
I have done all the parts of that but alert dialog is too small regarding tablet size.
I have also created custom alert dialog but it does not look good.
So tell me can i change the size of default alert dialog if yes then how.
OR
how to create custom alert dialog that looks like default alert dialog.
Thanks.
Please Refer this one
According to Android platform developer Dianne Hackborn in this discussion group post, Dialogs set their Window's top level layout width and height to WRAP_CONTENT. To make the Dialog bigger, you can set those parameters to FILL_PARENT.
Demo code:
AlertDialog.Builder adb = new AlertDialog.Builder(this);
Dialog d = adb.setView(new View(this)).create();
// (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
d.show();
d.getWindow().setAttributes(lp);
Note that the attributes are set after the Dialog is shown. The system is finicky about when they are set. (I guess that the layout engine must set them the first time the dialog is shown, or something.)
It would be better to do this by extending Theme.Dialog, then you wouldn't have to play a guessing game about when to call setAttributes. (Although it's a bit more work to have the dialog automatically adopt an appropriate light or dark theme, or the Honeycomb Holo theme. That can be done according to http://developer.android.com/guide/topics/ui/themes.html#SelectATheme )

Categories

Resources