android - 启动应用程序时关闭软键盘

标签 android keyboard

<分区>

我有一个简单的应用程序,有 2 个编辑和一个按钮,问题是当我开始运行我的应用程序时,软键盘自动出现,而我没有做任何事情。我想当我点击 Edittext 时,会出现软键盘?谢谢大家

主 Activity .xml

<EditText
                android:id="@+id/username"
                android:hint="Email/Phone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
<EditText
                android:id="@+id/password"
                android:hint="Password"
                android:inputType="textPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
<Button
            android:id="@+id/btn_login"
            android:text="Login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

我已经阅读了一些帖子并做了这些事情,但它们只有在我点击按钮时才有效:

InputMethodManager imm;
imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(username.getWindowToken(),0);

最佳答案

尝试在你的 list 中使用 android:windowSoftInputMode="stateHidden" ,你正在像下面的代码那样破坏你的 Activity

<activity
    android:name=".YourActivity"
    android:parentActivityName="XXX.XXX.XXXX"
    android:windowSoftInputMode="stateHidden" />

关于android - 启动应用程序时关闭软键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47091835/

相关文章:

带有可点击链接的 Android TextView : how to capture clicks?

ios - 当键盘出现时 View 仅大于屏幕时,如何在 iOS 中滚动?

ios - 有没有办法将 iPhone 键盘设置为全部大写而不通过委托(delegate)

mobile - 如何在没有 Home/End 键和 Fn 键的键盘上导航代码?

c# - 使用 GlobalMouseKeyHook 从空闲到操作 (C#)

events - 如何使用特定的KeyCode调度KeyboardEvent

java - 在 Appium Java Android 测试中单击菜单项时页面源未更新

android - 订阅 BLE Gatt 通知 Android

android - 当 recyclerview 在 scrollview 内时不调用 recycylerview addOnScrollListener

java.lang.NoClassDefFoundError : javafxports. android.FXDalvikEntity$2