Last active
February 28, 2021 16:35
-
-
Save shibbirweb/c2bbf95a0a3bc311e6bab1cd0c26fb35 to your computer and use it in GitHub Desktop.
Auto hide keyboard click on outside of edit text
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
| package me.shibbir.app | |
| import android.content.Context | |
| import android.view.MotionEvent | |
| import android.view.inputmethod.InputMethodManager | |
| import androidx.appcompat.app.AppCompatActivity | |
| open class BaseAppCompactActivity : AppCompatActivity() { | |
| override fun dispatchTouchEvent(ev: MotionEvent?): Boolean { | |
| if (currentFocus != null) { | |
| val imm: InputMethodManager = | |
| getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | |
| imm.hideSoftInputFromWindow(currentFocus!!.windowToken, 0) | |
| } | |
| return super.dispatchTouchEvent(ev) | |
| } | |
| } |
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
| // Usage | |
| // Just extend BaseAppCompactActivity | |
| class MainActivity : BaseAppCompactActivity() { | |
| // ...your code starts here | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment