desc:处理输入法

main
xiaowusky 2 years ago
parent ab4b244d11
commit be71a7119e

@ -6,6 +6,7 @@ import android.view.View
import com.yinuo.safetywatcher.R import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivitySensorSettingBinding import com.yinuo.safetywatcher.databinding.ActivitySensorSettingBinding
import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity
import com.yinuo.safetywatcher.watcher.utils.hideIme
import com.yinuo.safetywatcher.watcher.utils.showIme import com.yinuo.safetywatcher.watcher.utils.showIme
class SensorSettingActivity : NoOptionsActivity() { class SensorSettingActivity : NoOptionsActivity() {
@ -51,5 +52,11 @@ class SensorSettingActivity : NoOptionsActivity() {
return@OnKeyListener false return@OnKeyListener false
} }
) )
mBinding.etName.setOnFocusChangeListener { v, hasFocus ->
if (!hasFocus){
mBinding.etName.hideIme()
}
}
} }
} }

@ -32,4 +32,9 @@ fun View?.trySetCommonBg() {
fun EditText.showIme(){ fun EditText.showIme(){
val manager = this.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager val manager = this.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
manager?.showSoftInput(this, 0) manager?.showSoftInput(this, 0)
}
fun EditText.hideIme(){
val manager = this.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
manager?.hideSoftInputFromWindow(this.windowToken, 0)
} }
Loading…
Cancel
Save