为什么Android键盘添加一个ListView时弹出 [英] Why do the Android Keyboard pops up when adding a ListView
问题描述
我加入一个的ListView
我的布局时,面临着一个奇怪的问题。
I'm facing a weird problem when adding a ListView
to my layout.
我的布局包含2 的EditText
,当我开始活动时,键盘不会自动弹出。但是,当我加入的ListView
在布局的任何地方,键盘弹出活动开始时。
My layout contains 2 EditText
and when I start the activity, the keyboard doesn't pop automatically. But when I add a ListView
anywhere in the layout, the keyboard pop up when the activity starts.
我知道有很多方法可以隐藏键盘像这样的: getWindow()setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
,你可能已经看到了其他解决方案像这里和<一个问题href=\"http://stackoverflow.com/questions/4668210/automatic-popping-up-keyboard-on-start-activity\">here但我的问题不在于如何prevent这一点,但 为什么的会出现这种情况?
I know there are many ways to hide the keyboard like this one: getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
and you may have seen other solutions to the problems like here and here but my question is not how to prevent this but why is this happening ?
我创建了一个简单的例子来说明这种情况。
I have created a simple example to demonstrate this behavior
<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
(甚至wihtout与任何填充它),是显示了接口的键盘。
If this ListView
doesn't exist, the keyboard don't show up. If I replace the ListView
by other views, it still doesn't show up. Only when I add a simple ListView
(even wihtout populating it with anything), is the keboard showing up.
为什么的会出现这种情况?
Why is this happening?
推荐答案
试试这个在您的清单文件
Try this on your manifest file
<activity
android:name=".MyActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="stateHidden" />
这篇关于为什么Android键盘添加一个ListView时弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!