当前位置: 首页 > news >正文

Android - 点击EdieText之外的控件隐藏软键盘

//工具类

...
public static void hideKeyboard(Context ctx) {
		if (ctx != null) {
			View view = ((Activity) ctx).getCurrentFocus();
			if (view != null) {
				InputMethodManager inputManager = (InputMethodManager) ctx
						.getSystemService(Context.INPUT_METHOD_SERVICE);
				inputManager.hideSoftInputFromWindow(view.getWindowToken(),
						InputMethodManager.HIDE_NOT_ALWAYS);
			}
		}
	}


//点击除EDITTEXT之外的控件隐藏软键盘,如果是viewgroup控件,递归执行
public static void setupUI(View view, final Context ctx) {


	    //Set up touch listener for non-text box views to hide keyboard.
	    if(!(view instanceof EditText)) {


	        view.setOnTouchListener(new OnTouchListener() {


	            public boolean onTouch(View v, MotionEvent event) {
	            	hideKeyboard(ctx);
	                return false;
	            }


	        });
	    }


	    //If a layout container, iterate over children and seed recursion.
	    if (view instanceof ViewGroup) {


	        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {


	            View innerView = ((ViewGroup) view).getChildAt(i);


	            setupUI(innerView, ctx);
	        }
	    }
	}
...
}


调用时只需要传递最外层的layout即可。
	UtilApp.setupUI((RelativeLayout) findViewById(R.id.login_parent), mContext);


相关文章:

  • ASP.Net MVC + Data Table 实现分页+排序
  • SSL 链接安全协议的enum
  • C# https客户端获取证书的工具方法
  • [重构心得] 接一个烂Project怎么办
  • CentOS 5.1 做NAT代理,实现封迅雷,BT,pplive.
  • C# 中的Retry 模型
  • Apple应用消息通知 swift前端c#后端
  • MySQL数据库灾难恢复
  • 使用C# Diagnostics.DebuggerDisplay属性提高调试信息可读性
  • PDI简单介绍之ETL工具-----spoon
  • python flask web环境配置步骤
  • python flask SQLAlchemy 的用法
  • Blog须知
  • Azure VM Scalable Sets -- 适用IAAS架构
  • 数据库设计技巧14则
  • 时间复杂度分析经典问题——最大子序列和
  • [iOS]Core Data浅析一 -- 启用Core Data
  • [分享]iOS开发-关于在xcode中引用文件夹右边出现问号的解决办法
  • 【前端学习】-粗谈选择器
  • interface和setter,getter
  • java 多线程基础, 我觉得还是有必要看看的
  • JavaScript实现分页效果
  • Java多线程(4):使用线程池执行定时任务
  • leetcode386. Lexicographical Numbers
  • LintCode 31. partitionArray 数组划分
  • SSH 免密登录
  • STAR法则
  • TiDB 源码阅读系列文章(十)Chunk 和执行框架简介
  • Transformer-XL: Unleashing the Potential of Attention Models
  • vue学习系列(二)vue-cli
  • 爱情 北京女病人
  • 安卓应用性能调试和优化经验分享
  • 不上全站https的网站你们就等着被恶心死吧
  • 对JS继承的一点思考
  • 好的网址,关于.net 4.0 ,vs 2010
  • 简单数学运算程序(不定期更新)
  • 理解在java “”i=i++;”所发生的事情
  • 普通函数和构造函数的区别
  • 小程序button引导用户授权
  • 在Unity中实现一个简单的消息管理器
  • ​ArcGIS Pro 如何批量删除字段
  • #define与typedef区别
  • #QT(一种朴素的计算器实现方法)
  • (3)选择元素——(14)接触DOM元素(Accessing DOM elements)
  • (Git) gitignore基础使用
  • (k8s中)docker netty OOM问题记录
  • (Spark3.2.0)Spark SQL 初探: 使用大数据分析2000万KF数据
  • (二)JAVA使用POI操作excel
  • (附程序)AD采集中的10种经典软件滤波程序优缺点分析
  • (篇九)MySQL常用内置函数
  • (一) storm的集群安装与配置
  • (原創) 如何動態建立二維陣列(多維陣列)? (.NET) (C#)
  • ***测试-HTTP方法
  • .bat批处理(八):各种形式的变量%0、%i、%%i、var、%var%、!var!的含义和区别
  • .dwp和.webpart的区别