[英]Keyboard won't open for EditText
我正在開發一個基本的聊天應用程序,我有以下代碼行:
@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("");}
我沒有錯誤並且應用程序運行,但它發送空白文本並且沒有提供輸入文本的選項。 也就是說,鍵盤打不開。 我該如何解決這個問題?
嘗試解決您的問題:
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.