Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为什么在添加ListView时会弹出Android键盘大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的布局中添加ListView时,我遇到了一个奇怪的问题.

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

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

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

<LinearLayout xmlns:android="http://scheR_957_11845@as.android.com/apk/res/android"
    xmlns:tools="http://scheR_957_11845@as.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才会显示出来.

为什么会这样?

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

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

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。