I have ran into some issue with android. The situation is currently, when I tap the editText field in the alert dialog, the dialog will shift up to make way for the keyboard. However, I have calculated that there is enough space between my dialog and the keyboard. The reason behind is to have the dialog box hide the content that is underneath it.
Question
Is there a way to stop the alert dialog box from shifting upwards ?
Add or change in AndroidManifest.xml for that activity tag.
<activity
android:name=".YourActivity"
android:windowSoftInputMode="adjustNothing" />
As long as you always need to show the keyboard immediately once the dialog opens rather than once a specific form widget inside gets focus (for instance, if your dialog just shows an EditText and a button), you can do the following:
AlertDialog alertToShow = alert.create();
alertToShow.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
alertToShow.show();
Rather than calling .show() on your builder immediately, you can instead call .create() which allows you to do some extra processing on it before you display it onto the screen.
Related
I have a button in an activity, on clicking that button, I direct the user to a search activity with a search view in the toolbar..
I'm using android.support.v7.widget.SearchView, I managed to expand it automatically using searchView.setIconifiedByDefault(false) in onCreateOptionsMenu..
I also open the keypad automatically in activity onCreate, yet I still have to click in the searchView to start typing there, I want the cursor to be set there automatically..
any help?
call setIconifiedByDefault(false) when the searchview is intialized.
Sets the default or resting state of the search field. If true, a single search icon is shown by default and expands to show the text field and other buttons when pressed. Also, if the default state is iconified, then it collapses to that state when the close button is pressed. Changes to this property will take effect immediately.
Try the below, it worked for me once.
searchView.setIconifiedByDefault(true);
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
Update: If you are Using android.support.v7.widget.SearchView the behaviour is very different. clearFocus is needed if you don’t want the keyboard pop-up all the time.
Also in the searchview layout, use <requestFocus /> tag.
I'm having a problem with the softkeyboard not showing when i click on a EditText.
The activity goes like this.
1. Activity starts
2. Dialog box opens with a custom keyboard
3. And then I try to click on an empty EditText field to put in data, but nothing happens. The field get focus, but keyboard doesn't show up.
I haven't done anything funky with disabling keyboard..
Anyone know whats going on?
If you're using AVD manager add a hardware property Keyboard support and set it to false.
That should disable the shown keyboard, and show the virtual one.
How do you hide the keypad?
I'm currently using the following code to hide the keypad. Is there a better way to do this?
Window window = getWindow();
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
You have the right idea for hiding the soft keyboard. You could probably use the SOFT_INPUT_STATE_HIDDEN flag instead of the ALWAYS_HIDDEN one, this would allow it so it will re-open when the user clicks in the EditText without the need to call setSoftInputMode() again.
I have created in Java swing an option dialog with the JOptionPane.showOptionDialog method. This dialog includes different buttons, and among those a Cancel button. I would like to attach a listener method to this Cancel button so that once selected, the dialog is disposed.
My question is: how do I "retrieve" (or return) the dialog generated by the JOptionPane.showOptionDialog method?
I will assume you have read "How to Make Dialogs" tutorial from Oracle?
The return value from showOptionDialog() is an int, which indicates which button was chosen. Regardless of pressing OK, cancel or whatever, the window should dispose of itself. If you need more information back from the window then just which button was pressed, look at the other options like showInputDialog().
In the method "OnCreate" of my actvity, I'm displaying a little progress dialog while loading data. It's done every time the "OnCreate" method is called so even when the screen orientation change.$
In the nominal case, there is no problem even if the user change the screen orientation.
But, if the user opens another dialog (used to select an item in a list), then change the orientation, the progress dialog is displayed behind the "list" dialog and is not impacted by the "removeDialog".
Do you have any clues on that behavior ?
Thanks
call "removeDialog" or "dismissDialog" before "startDialog" with try-catch and so on. You can call "removeDialog" or "dismissDialog" several times...