为什么在添加ListView时会d出Android键盘

为什么在添加ListView时会d出Android键盘,第1张

概述在我的布局中添加ListView时,我遇到了一个奇怪的问题. 我的布局包含2个EditText,当我启动活动时,键盘不会自动d出.但是当我在布局中的任何位置添加ListView时,键盘会在活动开始时d出. 我知道有很多方法可以像这样隐藏键盘:getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN 在我的布局中添加ListVIEw时,我遇到了一个奇怪的问题.

我的布局包含2个EditText,当我启动活动时,键盘不会自动d出.但是当我在布局中的任何位置添加ListVIEw时,键盘会在活动开始时d出.

我知道有很多方法可以像这样隐藏键盘:getwindow().setSoftinputMode(WindowManager.LayoutParams.soFT_input_STATE_HIDDEN)你可能已经看到了其他问题,如here和here,但我的问题不是如何防止这个但是为什么会这样?

我创建了一个简单的例子来演示这种行为

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="@androID:color/black"    androID:orIEntation="vertical"    androID:paddingBottom="@dimen/activity_vertical_margin"    androID:paddingleft="@dimen/activity_horizontal_margin"    androID:paddingRight="@dimen/activity_horizontal_margin"    androID:paddingtop="@dimen/activity_vertical_margin"    tools:context="chadi.projects.code.TestKeyboardActivity" >    <EditText        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:background="@androID:color/white" />    <EditText        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_margintop="20dp"        androID:background="@androID:color/white" />    <ListVIEw        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_margintop="20dp" /></linearLayout>

如果此ListVIEw不存在,则键盘不会显示.如果我用其他视图替换ListVIEw,它仍然不会显示.只有当我添加一个简单的ListVIEw(甚至没有任何东西填充它)时,keboard才会显示出来.

为什么会这样?

解决方法 在清单文件上试试这个

<activity    androID:name=".MyActivity"    androID:configChanges="orIEntation|screenSize|keyboardHIDden"    androID:windowsoftinputMode="stateHIDden" />
总结

以上是内存溢出为你收集整理的为什么在添加ListView时会d出Android键盘全部内容,希望文章能够帮你解决为什么在添加ListView时会d出Android键盘所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1125476.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存