Advertisement
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 button: Button = findViewById(R.id.button)
- button.setOnClickListener {
- startActivity(Intent(this, DetailsActivity::class.java))
- }
- }
- override fun onStart() {
- super.onStart()
- // show the keyboard if has focus
- currentFocus?.let {
- showSoftKeyboard(it)
- }
- }
- private fun showSoftKeyboard(view: View) {
- if (view.requestFocus()) {
- val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
- // here is one more tricky issue
- // imm.showSoftInputMethod doesn't work well
- // and imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0) doesn't work well for all cases too
- imm?.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement