How to set windowsoftinputmode programmatically from Fragments?
try this I found :
aim to use two different modes for tabs. The modes are SOFT_INPUT_ADJUST_RESIZE
and SOFT_INPUT_ADJUST_NOTHING
.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
The code line above simply doesn't work by itself. App always behaves in a state ADJUST_NOTHING. However, if windowSoftInputMode="adjustResize" is inserted into tag in AndroidManifest.xml file, app window is resized as default. Additionally, when you call following line in fragment
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
it will behave as expected and nothing is resized.worked by me!
Adding implementation for iBEK's comment.Two things are required to be done for windowsSoftInputMode to work properly :
First is add following flag :
windowSoftInputMode="adjustResize"
in AndroidManifest.xml file as shown below :
<activity android:name="com.test.TestActivity" android:windowSoftInputMode="adjustResize"/>
Specifying this flag is madatory for windowsSoftInputMode to work.
Secondly add following in onCreate of your Activity, TestActivity in this case :
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams. SOFT_INPUT_ADJUST_RESIZE);
Now it should work for all fragments that activity is hosting.. I hope this answers your question @iBEK.