I'm a newbie with android, I write an application which using the Dialog to display data when user select on one thing. This is how the dialog looks:
https://docs.google.com/file/d/0B3NUAgD0tB0YOS16azFCWXdSVVE/edit
But when I tap on the last EditText to enter some data, the dialog still shows, when I type the first character, the dialog scrolls down. The dialog stays behind the keyboard, with some parts totally obscured.
Could anyone tell me how to show the whole dialog above the soft keyboard? This is how I'd like it to look:
https://docs.google.com/file/d/0B3NUAgD0tB0YOFVQYUF0U0JvOEk/edit
Thanks
Clark
Have you tried ths one?
Worked for me:
http://developer.android.com/reference/android/view/Window.html#setSoftInputMode(int).
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
You may need to set dialog's width and height manually in order to make soft input mode work like this:
WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
params.gravity = Gravity.CENTER;
window.setAttributes(params);
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
create a Xml file name style.xml
<style name="FullHeightDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowSoftInputMode">stateUnchanged</item>
<item name="android:windowBackground">#color/dialog_transparent</item>
</style>
then Implement
this works for me hoping it will work for you also.
final Dialog dialog = new Dialog(this , R.style.FullHeightDialog);
and also do changes in your manifest file
android:windowSoftInputMode="adjustResize|adjustPan"
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.show();
Window window = dialog.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Related
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 :)
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 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.
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 )
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>