【问题标题】:Close Soft Keyboard on start App [duplicate]在启动应用程序时关闭软键盘 [重复]
【发布时间】:2018-04-15 22:52:46
【问题描述】:

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

MainActivity.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);

【问题讨论】:

  • android:descendantFocusability="beforeDescendants" 在父布局中

标签: android keyboard


【解决方案1】:

尝试在您的清单中使用 android:windowSoftInputMode="stateHidden" 来破坏您的活动,如下面的代码

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

【讨论】:

  • 非常感谢你。我会接受。美好的一天:)
  • @tuấnvũhữu 很乐意帮助您享受编码
猜你喜欢
  • 1970-01-01
  • 2012-08-02
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
  • 2018-09-08
  • 2019-11-16
  • 1970-01-01
  • 2011-09-01
相关资源
最近更新 更多