gpt4 book ai didi

android - 为什么在添加 ListView 时会弹出 Android 键盘

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:12 25 4
gpt4 key购买 nike

在我的布局中添加 ListView 时,我遇到了一个奇怪的问题。

我的布局包含 2 个 EditText,当我开始 Activity 时,键盘不会自动弹出。但是当我在布局中的任何位置添加 ListView 时,键盘会在 Activity 开始时弹出。

我知道有很多方法可以像这样隐藏键盘:getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN),您可能已经看到了其他解决问题的方法,例如 herehere但我的问题不是如何防止这种情况,而是为什么会发生这种情况?

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

<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 替换为其他 View ,它仍然不会显示。只有当我添加一个简单的 ListView(甚至没有用任何东西填充它)时,keboard 才会出现。

为什么会发生这种情况?

最佳答案

在你的 list 文件上试试这个

<activity
android:name=".MyActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="stateHidden" />

关于android - 为什么在添加 ListView 时会弹出 Android 键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30231829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com