How to Change Android:Windowsoftinputmode Value from Java Class

Is there any way to change android:windowSoftInputMode value from java class?

Use the following to change the softInputMode for an Activity.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

Use the following to change the softInput type for an EditText.

mEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);

Thanks to @Eliezer for correction

How to set windowSoftInputMode programmatically on different screens in react-native?

Try this component react-native-android-keyboard-adjust

When the component in which you don't want to move up views mounts, set AndroidKeyboardAdjust.setAdjustPan() and when that component unmount reset it to AndroidKeyboardAdjust.setAdjustResize() or whatever option that suits your criteria

See this answer

windowSoftInputMode=adjustResize not working with translucent action/navbar

You are missing the following property:

android:fitsSystemWindows="true"

in the root RelativeLayout of the fragment .xml layout.

Update:

Last year there was an interesting talk by Chris Bane that explains in good detail how this works:

https://www.youtube.com/watch?v=_mGDMVRO3iE

Using adjustPan or adjustResize specific to a fragment

You can change the behavior programmatically, see this answer for that.

So what I would do: if fragment A is resumed, use getActivity() to get a reference to its parent activity, and then use the command from the question to change the behavior.

Then do the same with fragment B, but use the other parameter when setting the soft input mode behavior.

  • adjustResize would be: WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
  • adjustPan would be: WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN

Why doesn't my layout move up enough with adjustPan?

create an object like InputMethodManager methodManager at class level.

add these lines to your onCreate() method,

methodManager = (InputMethodManager) this.getSystemService(this.INPUT_METHOD_SERVICE);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

and in your onClick() method, show keyboard like,

methodManager.toggleSoftInputFromWindow(
your_view_name.getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);

If this word getApplicationWindowToken throws an error then replace it with getWindowToken
hope it helps.

Android - ScrollView activity hosted in TabActivity and windowSoftInputMode

In the absence of any direct solution for this, I have resorted to a kind of hack. I have set my TabHost activity to adjustResize and then written code to hide/unhide the tab bar controls (TabWidget) when the soft keyboard appears/disappears. I managed to get a pretty good result in the end, using the technique here : Adjust layout when soft keyboard is on to detect the keyboard appearing/disappearing.



Related Topics



Leave a reply



Submit