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文本框。 

  • 相关阅读:
    重磅官宣:Nacos2.0发布,性能提升10倍
    埃森哲携手阿里云共建基于云原生的消费者运营中台解决方案
    3. Windows根据端口查进程---ADB 相关报错 ADB server didn't ACK cannot bind ':5037'
    2.Could not open Selected VM debug port (8700). Make sure you do not have another instance of DDMS or of the eclipse plugin running
    1.运行Android Studio,一直提示:Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.
    SpringBoot_配置-yaml配置文件值获取
    SpringBoot_入门-使用向导快速创建Spring Boot应用
    SpringBoot_入门-HelloWorld细节-自动配置
    SpringBoot_入门-微服务简介
    SpringBoot_入门-Spring Boot简介
  • 原文地址:https://www.cnblogs.com/Jerseyblog/p/5219797.html
Copyright © 2011-2022 走看看