How to hide the soft keyboard from inside a fragment?

前端 未结 14 1654
予麋鹿
予麋鹿 2020-12-01 00:08

I have a FragmentActivity using a ViewPager to serve several fragments. Each is a ListFragment with the following layout:



        
14条回答
  •  被撕碎了的回忆
    2020-12-01 00:24

    Use this:

    Button loginBtn = view.findViewById(R.id.loginBtn);
    loginBtn.setOnClickListener(new View.OnClickListener() {
       public void onClick(View v) {
          InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(getActivity().INPUT_METHOD_SERVICE);
          imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
       }
    });
    

提交回复
热议问题