我有一个编辑文本和一个微调器。当我触摸编辑文本时,键盘会出现,完成文本编辑后,我触摸微调器的下拉箭头,但键盘不会自动消失。请给我一些解决方案。
我试过这段代码
InputMethodManager imm=(InputMethodManager)getApplicationContext().getSystemService(SetUpProfileActivity.this.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mDateOfBirth.getWindowToken(), 0);
这是 XML
<LinearLayout
android:id="@+id/outerlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
>
<TextView
android:id="@+id/name_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/profile_name"
android:textColor="#ffffff" />
<EditText
android:id="@+id/profile_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/txtbox"
android:singleLine="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/dateofbirth"
android:textColor="#ffffff" />
<Spinner
android:id="@+id/dob"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/dropdown" />
试试这个代码,我希望它对你有用。
mSpinner.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
InputMethodManager imm=(InputMethodManager)getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
return false;
}
}) ;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)