【问题标题】:Keyboard won't open for EditText键盘不会为 EditText 打开
【发布时间】:2020-10-04 14:01:04
【问题描述】:

我正在开发一个基本的聊天应用程序,我有以下几行代码:

@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("");}

我没有错误并且应用程序运行,但它发送空白文本并且没有提供输入文本的选项。也就是说,键盘打不开。我该如何解决这个问题?

【问题讨论】:

  • 可以分享一下这个EditText相关的xml吗?也许它不是实际的编辑文本?
  • 在明文之后,试试这个。 EditText editText = (EditText) findViewById(R.id.myTextViewId); editText.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
  • 最后的建议很有帮助,谢谢!

标签: java android firebase android-studio androidx


【解决方案1】:

尝试解决您的问题:

1.对manifest文件稍作改动即可解决

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

2。将这些行添加到editext

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

3.您也可以在代码中使用它

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多