zoukankan      html  css  js  c++  java
  • Android开发:在EditText中关闭软键盘 转来的

    1、EditText有焦点(focusable为true)阻止输入法弹出  

    Java代码  收藏代码
    1. editText=(EditText)findViewById(R.id.txtBody);  
    2.   
    3.         editText.setOnTouchListener(new OnTouchListener() {               
    4.   
    5.             public boolean onTouch(View v, MotionEvent event) {    
    6.   
    7.                 editText.setInputType(InputType.TYPE_NULL); // 关闭软键盘        
    8.   
    9.                 return false;  
    10.   
    11.             }  
    12.   
    13.         });    



    2、当EidtText无焦点(focusable=false)时阻止输入法弹出  

    Java代码  收藏代码
    1. InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);       
    2.   
    3.        imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);      



    1.调用显示系统默认的输入法 

    方法一、 

    Java代码  收藏代码
    1. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
    2.   
    3. imm.showSoftInput(m_receiverView(接受软键盘输入的视图(View)),InputMethodManager.SHOW_FORCED(提供当前操作的标记,SHOW_FORCED表示强制显示));  




    方法二、 

    Java代码  收藏代码
    1. InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
    2. m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); (这个方法可以实现输入法在窗口上切换显示,如果输入法在窗口上已经显示,则隐藏,如果隐藏,则显示输入法到窗口上)  




    2.调用隐藏系统默认的输入法 

    Java代码  收藏代码
    1. ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);  (WidgetSearchActivity是当前的Activity)  




    3.获取输入法打开的状态 

    Java代码  收藏代码
    1. InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  
    2. boolean isOpen=imm.isActive();  
    3. isOpen若返回true,则表示输入法打开  





    原文:http://sunxin1001.iteye.com/blog/854182 
    http://getcn.net/index.php?mod=skill&action=detail&id=43978 


    另外 
    参数             含义 
    WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN 
    软键盘直接覆盖Activity,通常这是默认值 
    WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE 
    Activity高度会变化,让出软键盘的空间。和WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN 为2选1的值 
    WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE 
    Activity一打开就直接显示软键盘窗口,如果该窗口需要的话(即有EditText,或有ditable的控件) 
    WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN 
    Activity打开后并不直接显示软键盘窗口,直到用户自己touch文本框。 

  • 相关阅读:
    Spring Boot 使用 Dom4j XStream 操作 Xml
    Spring Boot 使用 JAX-WS 调用 WebService 服务
    Spring Boot 使用 CXF 调用 WebService 服务
    Spring Boot 开发 WebService 服务
    Spring Boot 中使用 HttpClient 进行 POST GET PUT DELETE
    Spring Boot Ftp Client 客户端示例支持断点续传
    Spring Boot 发送邮件
    Spring Boot 定时任务 Quartz 使用教程
    Spring Boot 缓存应用 Memcached 入门教程
    ThreadLocal,Java中特殊的线程绑定机制
  • 原文地址:https://www.cnblogs.com/Jerseyblog/p/5219797.html
Copyright © 2011-2022 走看看