Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide keyboard when showing DialogFragment on tablet?

I am using DialogFragment with ListView (to list all customer) and EditText (to search from list), it's working fine. But, whenever the dialog shows from the fragment, the keyboard is always shown and the user needs to resign. Is there any way to hide this at the first time while showing the dialog fragment? then, when the user clicks on edit text, the keyboard should appear.

I have tried setting android:focusable="false" in my XML but, it always hides the keyboard after click on EditText also not showing.

Then I tried setting android:focusableInTouchMode="true" but, getting same as above

like image 706
Sugan S Avatar asked Aug 30 '13 10:08

Sugan S


People also ask

How do I make my keyboard invisible on Android?

It's the left-pointing arrow button at the bottom of the screen, either at the bottom-left or bottom-right corner. The keyboard is now hidden. The back button may be a physical button or on the touch screen.

How do you hide on keyboard?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow , passing in the token of the window containing your focused view. This will force the keyboard to be hidden in all situations. In some cases, you will want to pass in InputMethodManager.

How do I prevent the soft keyboard from pushing my view up in fragment?

Setting android:isScrollContainer = "false" inside the ScrollView worked for me. According to the documentation, settings "isScrollContainer" to true means that the scroll view can be resized to shrink its overall window so that there is space for an input method.


2 Answers

In your DialogFragment onCreateView() add the following:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState)
{
 View view = super.onCreateView( inflater, container, savedInstanceState );
 //to hide keyboard when showing dialog fragment
 getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
 return view;
}
like image 165
Sugan S Avatar answered Oct 16 '22 12:10

Sugan S


This should solve your problem

android:windowSoftInputMode="stateHidden"

or

android:windowSoftInputMode="stateUnchanged" 
like image 2
Naskov Avatar answered Oct 16 '22 12:10

Naskov