-
Notifications
You must be signed in to change notification settings - Fork 0
/
View.kt
42 lines (36 loc) · 1.11 KB
/
View.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package net.nuvem.mobile.todolar.extensions
import android.app.Activity
import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
fun View.showKeyboard(editText: EditText) {
val inputMethodManager = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
editText.requestFocus()
inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
}
fun View.hideKeyboard(): Boolean {
try {
val inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
return inputMethodManager.hideSoftInputFromWindow(windowToken, 0)
} catch (ignored: RuntimeException) { }
return false
}
fun View.visible() : View {
if (visibility != View.VISIBLE) {
visibility = View.VISIBLE
}
return this
}
fun View.invisible() : View {
if (visibility != View.INVISIBLE) {
visibility = View.INVISIBLE
}
return this
}
fun View.gone() : View {
if (visibility != View.GONE) {
visibility = View.GONE
}
return this
}