I have a Custom Dialog Box that contains an EditText. Now, Whenever I show the Dialog usingDialog.show();, the EditText immediately grabs focus and displays the Soft-Keyboard. I attempted to add this to the manifest:
android:windowSoftInputMode="stateHidden"
Based on this answer: https://stackoverflow.com/a/2611031/3011902
I also tried the following on the EditText:
EditText.setSelected(false);
And:
LinearLayout hidden = (LinearLayout) loginDialog.findViewById(R.id.hidden);
hidden.setVisibility(View.INVISIBLE);
hidden.setFocusable(true);
hidden.requestFocus();
loginDialog.show();
I also tried to manually hide the keyboard right after the dialog is shown, but that feels a bit illegitimate. Is there any easy way to only display the keyboard when the EditText of the Dialog is selected.
You can try redirecting the focus to another view or just invisible view inside your Custom Dialog Box with adding
android:focusable="true" and android:focusableInTouchMode="true"
or
setFocusable(true) and setFocusableInTouchMode(true)
If you have any question about my answer feel free to ask in the comment!
Related
In my app the first view of all my screens is an EditText, so every time I go to a screen the onscreen keypad pops up. how can I disable this popping up and enable it when manually clicked on the EditText????
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
This can be used in Fragment Class to move the Edit text up and Scroll till the end. The problem is that when I click on an EditText the keyboard pops up. I think I have to do it in java. Thank you!!!
You need to set windowSoftInputMode attribute to each activity in AndroidManifest.xml file.
<activity
android:name="YourActivityPath"
android:windowSoftInputMode="stateAlwaysHidden"/>
In the parent layout of you view add android:focusableInTouchMode="true" this will put the focus on the parent view and you won't need to do anything else to invoke the keyboard, it will automatically show when the edit text is clicked
I have a custom Spinner class and which uses an alert Dialog to display its contents and it has "Submit" and "Cancel" buttons. The alert dialog has one edit text and others are just read-only labels. On click of edit text the virtual keyboard appears and it moves the layout moves bit up but the buttons remain hidden. I want the buttons to be visible also.
Things I have tried so far:-
Manifest :-
android:windowSoftInputMode="stateVisible|adjustResize"
android:windowSoftInputMode="adjustPan"
In Activity Class:-
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
It is just moving screen enough not to hide the edit text where as my button are still remain invisible.
You can't. The height of the keyboard is decided by the keyboard- it can't be made smaller. The rules for the keyboard are that if it the cursor would be covered, unless all movement is shut off it will scroll everything the minimum such that the cursor is on screen. There is no way to tell the OS to scroll it more than that. There is resize, but I'm not sure that will work for an alert dialog- I think those still go full screen. The keyboard API just isn't made for your usecase.
There is a CardView with an EditText and when the keyboard opens, it is placed right below the EditText. But as shown below, the keyboard is too close to the EditText and it is hard to press the "send" button because there is not enough space.
EditText:
EditText with focus:
Is there any way to show the keyboard after the end of the CardView?
I saw some similar questions here, but none of them provide a solution that I need. Some answers suggest to set a paddingBotton in EditText, but that is not what I want. I don't want space, I want to show the end of the CardView too.
Note that I don't want to resize the layout, so "adjustResize" is not the solution and I'm already using "adjustPan" in AndroidManifest.xml
<activity
...
android:windowSoftInputMode="adjustPan" />
Any thoughts?
If you are using scrollview. you can do one thing is to scroll your scrollview as your requirement
Please refer below code for example
ScrollView sv =(ScrollView)findViewById(R.id.scrl);
sv.scrollTo(0, sv.getBottom());
or
sv.fullScroll(View.FOCUS_DOWN);
this action you can perform on soft input of Enter key.
There is also one other solution you can hide the suggestion of keyboard by giving
android:inputType="textNoSuggestions"
I have some edittext on my layout, when I click on the edittext for filling it the softkeyboard appear and everything in fine, I can see the input and the softkeyboard but when I click on the edittexts at the bottom of the layout the softkeyboard appear and the edittext is not visible while I'm typing, I have to scroll down to see it. Is there any way to automatically scroll to the edittext so I can see when I'm typing and the softkeyboard at the same time?
You just need to add this to your activity tag in the manifest
android:windowSoftInputMode="adjustPan"
Have a look at this developers blog _ On-screen Input Methods.
Summing up I guess this line should help you:
android:windowSoftInputMode="stateVisible|adjustResize">
I have an EditText and an ImageButton beside it. When I click the EditText the soft keyboard shows up. Fine. When I click the ImageButton a custom dialog shows up and the soft keyboard gets automatically hidden. I want the keyboard to stay open though. How can I achieve this?
Found the solution. I used the common Dialog class to display my dialog. Using AlertDialog instead did the trick.