如何在微调器上隐藏虚拟键盘 [英] how to hide virtual keyboard on touch of a spinner

查看:61
本文介绍了如何在微调器上隐藏虚拟键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个edittext和一个微调框.当我轻触edittext时,键盘出现,完成文本编辑后,我轻触微调器的下拉箭头,但键盘不会自动消失.请给我一些解决方案. 我尝试了此代码

I have a edittext and a spinner. When I touch on the edittext the keyboard appears, after completed the text editing I touch on the dropdown arrow of the spinner but the keyboard doesn't disappears automatically. Please give me some solution. I tried this code

 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" />

推荐答案

尝试以下代码,希望它对您有用.

Try this code, I hope it will work for you.

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;
            }
        }) ;

这篇关于如何在微调器上隐藏虚拟键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆