zoukankan      html  css  js  c++  java
  • android 开启或者隐藏软键盘

    一、
    隐藏软键盘方法一(注:此方法本人使用时发现isActivie()失效,建议还是用其他方法。。):
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  
    //得到InputMethodManager的实例 
    if (imm.isActive()) { 
    //如果开启 
    imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); 
    //关闭软键盘,开启方法相同,这个方法是切换开启与关闭状态的 


    ------------------------------------------ 
    //隐藏软键盘方法二:
    int flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; 
    getWindow().addFlags(flags); 

    在onclick事件下.以下方法可行.(如果是EditText失去焦点/得到焦点,没有效果) 
    InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
    im.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
     
    二、

    // 关闭键盘
     public void KeyBoardCancle() {

      View view = getWindow().peekDecorView();
      if (view != null) {

       InputMethodManager inputmanger = (InputMethodManager) getSystemService(ActivityBase.INPUT_METHOD_SERVICE);
       inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
      }
     }

     
  • 相关阅读:
    poj3718 Facer's Chocolate Dream
    codeforces 917D Stranger Trees
    uoj#349 【WC2018】即时战略
    bzoj5153 [Wc2018]州区划分
    bzoj5152 [Wc2018]通道
    loj2001[SDOI2017]树点染色
    loj2000[SDOI2017]数字表格
    Atcoder arc092
    bzoj4826[hnoi2017]影魔
    bzoj4827 [hnoi2017]礼物
  • 原文地址:https://www.cnblogs.com/Mr-Nobody/p/3537921.html
Copyright © 2011-2022 走看看