Created
August 10, 2020 14:38
-
-
Save gabrielbmoro/89b601d153ee79acbd0899d877d285b4 to your computer and use it in GitHub Desktop.
Change the soft input mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Make sure that @param softInputMode is a value from WindowManager.LayoutParams, for example: | |
* - SOFT_INPUT_ADJUST_PAN | |
* | |
* @return the previous softInputMode | |
*/ | |
fun FragmentActivity.setSoftInputMode(softInputMode: Int): Int? { | |
val previousSoftInputMode: Int? = | |
try { | |
packageManager.getActivityInfo( | |
componentName, | |
PackageManager.GET_META_DATA | |
).softInputMode | |
} catch (nameNotFoundException: PackageManager.NameNotFoundException) { | |
null | |
} | |
return previousSoftInputMode?.also { | |
window.setSoftInputMode(softInputMode) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment