点击空白处隐藏软键盘

  1. 1, 给activity布局文件加入  id

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  

        xmlns:tools="http://schemas.android.com/tools"  

        android:layout_width="fill_parent"  

        android:layout_height="fill_parent"  

        android:scrollbars="vertical"  

        android:id="@+id/activity_main"  

        >  

  2. 2, 按照一般控件的方式进行事件监听。  

    activity_main=(LinearLayout) findViewById(R.id.activity_main);  

    activity_main.setOnTouchListener(new OnTouchListener()  

    {  

                  

        public boolean onTouch(View arg0, MotionEvent arg1)  

        {  

            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);  

            return imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);  

        }  

    });  

猜你喜欢

转载自blog.csdn.net/qq1073273116/article/details/50311531
今日推荐