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_BEHIND);
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.
Related
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.
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 :)
A have an Activity (minSDK for my app = 14) to which the #android:style/Theme.Holo.Dialog Theme is applied. I need to set an icon, so I used
this.requestWindowFeature(Window.FEATURE_LEFT_ICON);
this.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
R.drawable.share);
I guess the icon is set (because the title moved to the right) but for some reason it is not visible as if it was transparent:
I can't find any logical explanation for this behavior. Any ideas?
P.S. no, my drawable is not the same color as the window's background
If I'm not mistaken then you have to set your icon resource on custom Dialog after calling show on it.
dialog.show();
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.share);
Its still a mystery why does it work and not the other way :)
it is order:
1 ) this.requestWindowFeature(Window.FEATURE_LEFT_ICON);
2) this.setContentView(R.layout.xxx);
if is Dialog (dialog.show();)
3) this.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.share);
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);
I have a AlertDialog box with approximately 10 controls (text and TextView) on it. These controls are in a ScrollView with AlertDialog, plus I got 2 buttons positive and negative. The issue I have is when the soft keyboard pops up the two buttons are hidden behind the keyboard.
I was looking for something like redraw function on my inner View or the dialog box. Below is the screen shot of what I am talking about.
If your dialog was an activity using one of the Dialog themes you could effect this behavior by setting the adjustResize flag for the windowSoftInputMode parameter of the activity.
I'm using:
android:windowSoftInputMode="adjustResize|stateHidden"
I think you can still use this flag with regular dialogs, but I'm not sure how to apply it. You may have to create your AlertDialog with a custom theme that inherits the right parent theme and also sets that flag, or you might have to use ContextThemeWrappers and stuff.
Or maybe you can just use Window#setSoftInputMode.
alertDialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
I've found a best way to handle this. Because this is a dialog, So the code
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
doesn't work very well.
Besides this code, you must set a dialog style for this dialog. The style should like below:
<style name="DialogStyle" parent="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<item name="android:windowFullscreen">false</item>
......
......
</style>
NOTICE that the attribute parent is Theme.Black.NoTitleBar.Fullscreen like an activity's style. and the attribute android:windowFullScreen should be false.
Now, the dialog will be resized when the soft keyboard toggles.
Nothing worked for me except adjustPan
as per the documentation
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
So just simply use it in your onCreate() or onCreateView() method like:
getDialog().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Or simply put android:windowSoftInputMode="adjustPan" in manifest for the Activiry in which we are playing with dialogs
and use android:windowSoftInputMode="adjustResize|stateHidden" in each edittext which will help the user to navigate to next textbox easily.
Point to remember
Never use MATCH_PARENT to make the dialog full screen as adjustPan will not work here. If anyone wants to make the dialog to fit the screen, just use points till 0.96 (not more than this) for the height, so the keyboard will properly reach to the edittext. I did like below :
#Override
public void onStart()
{
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
{
//int height = ViewGroup.LayoutParams.MATCH_PARENT;
int width = ViewGroup.LayoutParams.MATCH_PARENT;
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
//int width = (int)(size.x * 0.96);
int h = (int)(size.y * 0.96);
dialog.getWindow().setLayout(width, h);
}
}
Look, If I will use the total height (MATCH_PARENT) then soft_keyboard will squize the dialog. But if I will use points for the height (here 0.96 which is almost near to match_parent), then it will properly work.
Hope it will help someone :)
maybe you don't need to resize Dialog
add android:imeOptions="actionNext" to EditText(all but last) (it will add "Next" button to the keyboard - go to next EditText)
and add android:imeOptions="actionDone" to last EditText ("Done" button - hide keyboard)
now user should be able to click buttons
if you're creating textboxes in code use EditText#setImeOptions function
HTH
Are you forced to have it as a popup? The popup looks so large, that you may just want to have it as a separate activity. In general, popups are used to provide a brief question or statement with a few options, not a full blown data entry form. Since you can't see much behind the large popup, you're not exposing any underlying controls anyways.
to show keyboard immediately and adjust size:
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
}
});
To those who are in the same situation as me.
in my case, the problem was activity having these attributes in style
<style name="SomeStyleName">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
If windowTranslucentStatus and windowTranslucentNavigation both are true,
the keyboard came up as it overlay dialog.
So I override those values to false, only for materialAlertDialog. (maybe AlertDialog or Dialog in your case)
<style name="SomeStyleName">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="materialAlertDialogTheme">#style/TranslucentMaterialAlertDialogTheme</item>
</style>
<style name="TranslucentMaterialAlertDialogTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
</style>