class MainActivity : AppCompatActivity() {
lateinit var activityMainBinding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityMainBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(activityMainBinding.root)
activityMainBinding.run {
thread {
SystemClock.sleep(500);
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(currentFocus, 0);
}
}
}
}
class MainActivity : AppCompatActivity() {
lateinit var activityMainBinding: ActivityMainBinding
lateinit var imm: InputMethodManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityMainBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(activityMainBinding.root)
imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
activityMainBinding.run {
thread {
SystemClock.sleep(500)
imm.showSoftInput(currentFocus,0)
}
}
}
}
requestFocus()
setText("문자열 생성")
setText("문자열 생성")
requestFocus()
setOnEditorActionListener { v, actionId, event ->
textView.text = text.toString()
false
}
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
if(currentFocus != null) {
imm.hideSoftInputFromWindow(currentFocus!!.windowToken, 0)
}
if(currentFocus != null) {
currentFocus!!.clearFocus()
}
* 키보드 제거 후 커서 제거
→ 포커스부터 제거하는 경우 currentFocus가 없어 오류 발생