Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to display keyboard automatically when activity started #54

Open
bchooxg opened this issue Dec 15, 2022 · 2 comments
Open

Comments

@bchooxg
Copy link

bchooxg commented Dec 15, 2022

I have the field on a password screen activity
I would like for the keyboard to be displayed when the activity created instead of having the user to tap on the field.

Can i just check on how can i do this

@ghost
Copy link

ghost commented Apr 8, 2023

Same question.

@HariAgus
Copy link

Hi, @bchooxg you can do like this in onCreate() :

// For show

fun View.showSoftKeyboard() {
        if (this.requestFocus()) {
            val imm: InputMethodManager = this.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
        }
    }

// For Hide

fun View.hideSoftKeyboard() {
     val imm = this.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
     imm.hideSoftInputFromWindow(this.windowToken, 0)
 }

After that, you can use like this : binding.circlePin.showSoftKeyboard()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants