【发布时间】: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" 在父布局中