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

AndroidAndroid TabhostAndroid Softkeyboard

Android Problem Overview


I want to act my tabs to have different windowSoftInputMode properties for each tab. How to access this property from java class when all handling of your tab is done from one single activity?

Is there any way to access this manifest property from java code?

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

According to Prasham's comment, I did this and it saved my life, thanks to him! The EditText and SoftWindowInput mode are quite buggy when you have a layout with ScrollView and you are filling it dynamically.

Since I had gone through this post but had continued to read other answers/comments (like Prashan's one), I decided to write it in a new post.

Below the code I used with my ScrollView:

Activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

Solution 3 - Android

I 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 <activity> tag in AndroidManifest.xml file, app window is resized as default. Additionally, when you call following line

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

it will behave as expected and nothing is resized.

P.S. improvement to the answer

Solution 4 - Android

In Xamarin Android You Can Do programatically Like This

 protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.DetailDesign);
             Window.SetSoftInputMode(SoftInput.AdjustPan);
        }

Solution 5 - Android

You can use the following code programmatically

android.view.inputmethod.InputMethodManager imm = (android.view.inputmethod.InputMethodManager) context
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

Thanks Deepak

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPrashamView Question on Stackoverflow
Solution 1 - AndroidAjOnFireView Answer on Stackoverflow
Solution 2 - AndroidamanView Answer on Stackoverflow
Solution 3 - AndroidShnkcView Answer on Stackoverflow
Solution 4 - AndroidZubair MunirView Answer on Stackoverflow
Solution 5 - AndroidSunil Kumar SahooView Answer on Stackoverflow