Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. class MainActivity : AppCompatActivity() {
  2.  
  3. override fun onCreate(savedInstanceState: Bundle?) {
  4. super.onCreate(savedInstanceState)
  5. setContentView(R.layout.activity_main)
  6.  
  7. val button: Button = findViewById(R.id.button)
  8. button.setOnClickListener {
  9. startActivity(Intent(this, DetailsActivity::class.java))
  10. }
  11. }
  12.  
  13. override fun onStart() {
  14. super.onStart()
  15.  
  16. // show the keyboard if has focus
  17. currentFocus?.let {
  18. showSoftKeyboard(it)
  19. }
  20. }
  21.  
  22. private fun showSoftKeyboard(view: View) {
  23. if (view.requestFocus()) {
  24. val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
  25.  
  26. // here is one more tricky issue
  27. // imm.showSoftInputMethod doesn't work well
  28. // and imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0) doesn't work well for all cases too
  29. imm?.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement