简体   繁体   中英

Keyboard won't open for EditText

I am developing a basic chat application and I have the following lines of code:

@Override
public void onClick(View view) {
        EditText input = findViewById(R.id.input);
// Read the input field and push a new instance
// of ChatMessage to the Firebase database
FirebaseDatabase.getInstance()
        .getReference()
        .push()
        .setValue(new ChatMessage(input.getText().toString(),
                Objects.requireNonNull(FirebaseAuth.getInstance()
                        .getCurrentUser())
                        .getDisplayName())
        );

// Clear the input
input.setText("");}

I have no errors and the app runs, but it sends blank texts and isn't giving an option to enter text. That is, the keyboard won't open. How can I resolve this?

Try it to solve your problem:

1.Make a small change to manifest file to solve it

<activity
    ...
    android:windowSoftInputMode="adjustResize"
    ... >
    </activity>

2. Add these lines to editext

android:focusable="true"
android:focusableInTouchMode="true"

3. Also you can use it in your code

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM