Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MainActivity : AppCompatActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- val items = listOf<AppCompatEditText>(et1, et2, et3, et4, et5, et6, et7, et8, et9, et10, et11, et12,
- et13, et14, et15, et16, et17, et18, et19, et20, et21, et22, et23)
- items.forEachIndexed { index, et -> et.hint = "index : $index" }
- scrollView.viewTreeObserver.addOnGlobalFocusChangeListener { old, _ ->
- // TODO : how to check next focus edittext
- old?.takeIf { keyboardIsShow() }?.apply {
- scrollView.smoothScrollTo(0, scrollView.scrollY.plus(120))
- }
- }
- }
- }
- // TODO : move to file UIExtensions
- fun Activity.keyboardIsShow(): Boolean = let {
- var flag = false
- val rect: Rect by lazy { Rect() }
- window.decorView.rootView?.apply {
- getWindowVisibleDisplayFrame(rect)
- flag = (bottom - rect.bottom) > (100 * resources.displayMetrics.density)
- }
- flag
- }
Add Comment
Please, Sign In to add comment