在android中打开活动时,如何防止键盘打开?
在我的android应用程序中,在我的个人资料编辑页面中,当我开始活动时,first edittext字段被聚焦(光标闪烁),并且键盘被显示 我怎样才能让它专注于启动(光标闪烁),但不让键盘出现?如果这是不可能的,那么就不要在启动时集中编辑文本 谢谢在android中打开活动时,如何防止键盘打开?,android,android-edittext,Android,Android Edittext,在我的android应用程序中,在我的个人资料编辑页面中,当我开始活动时,first edittext字段被聚焦(光标闪烁),并且键盘被显示 我怎样才能让它专注于启动(光标闪烁),但不让键盘出现?如果这是不可能的,那么就不要在启动时集中编辑文本 谢谢 <EditText android:id="@+id/textinput_firstname" android:layout_width="match_parent"
<EditText
android:id="@+id/textinput_firstname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="test" />
只需在
onCreate(…)
方法中添加这一行代码
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
对于大多数用户来说,EditText可能会发生这种情况,您只需转到布局文件并按如下方式设置布局的视图组属性:
android:focusable="true"
android:focusableInTouchMode="true"
比如说
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:focusable="true"
android:focusableInTouchMode="true">
<EditText
android:layout_width="match_parent"
android:layout_height="41dp"
/>
</LinearLayout>
注意:必须为布局中的第一个视图设置属性
不管是什么,这都会将默认焦点设置为false
@omega我的荣幸:)我必须等5分钟才能。。。该网站不允许我。这将破坏由android:WindowsOfInputMode=“adjustResize”设置的调整大小
活动
功能-行为类似于adjustPan
并停止调整大小…可能重复该问题是关于显示键盘的,该问题是关于隐藏键盘,是什么让你认为这是一个可能的复制品?