android - 不自动显示软键盘
问题描述
在我的 xml 布局中:
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/nameTextInputEditText"
style="@style/textViewOneLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/default_margin"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="@string/name"
android:textColor="@android:color/white"
android:textColorHint="@android:color/white"
android:textSize="17sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolBarContainer" />
但是当显示活动时,软键盘不显示。我必须单击TextInputEditText
以显示键盘。
这无济于事:
android:focusable="true"
android:focusableInTouchMode="true"
解决方案
尽管如此,这应该有效。
确保您的父布局不是可聚焦模式。还要确保父布局是相对或线性的。
如果所有这些都失败了,请尝试以下操作:在 setContentView 之后将其添加到 onCreate 中的主要活动中。让我们看看会发生什么。
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
推荐阅读
- docker - 运行撰写 yml 文件 docker-compose.yml 的 Docker 堆栈部署命令错误
- java - 使短信中的某些文本能够在 android 上弹出复制选项
- javascript - 溢出正在父 div 后面发送下拉列表,z-index 不起作用
- python - 如何将此函数转换为 python 中的列表理解?
- r - 使用 ggraph 绘制双连词共现时出现问题,某些行不显示
- json - Angular4中的嵌套JSON循环
- postgresql - PostgreSQL 安装在 5432 端口
- swift - SwiftSoup 将正文中的文本包装到 div
- excel - Excel 中的 ActiveX 文本框在失去焦点时闪烁旧值
- ignite - Apache Ignite CacheConfiguration 对每个数据集重复吗?