惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
T
The Blog of Author Tim Ferriss
C
Check Point Blog
博客园_首页
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
L
LangChain Blog
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
爱范儿
爱范儿
Vercel News
Vercel News
博客园 - Franky
V
V2EX
IT之家
IT之家
U
Unit 42
N
Netflix TechBlog - Medium
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
博客园 - 叶小钗
H
Help Net Security
V
Visual Studio Blog
GbyAI
GbyAI

博客园 - 清炒白菜

Unable to resume activity : android.database.StaleDataException: Attempted to access a cursor after it has been closed. 异常 Android的匿名Handler类引起的内存泄露 计算2个经纬度之间的距离 用bcp导入DateTime类型的数据 Linux下提示“omitting directory”错误的解决办法 Android的"返回“功能 获取当前Activity的Root View 用代码动态设置ImageView的align布局 Android中Sqlite数据库多线程并发问题 [转]Java的数组(Array)、Vector、ArrayList、HashMap的异同 HTML中element.style取值问题 用bcp导入大量数据(代替INSERT) ajax跨域访问问题 又一款分布式版本控制工具Mercurial bcp导入导出数据发生异常解决方案 - 清炒白菜 - 博客园 导出Google Reader中加星的内容项 - 清炒白菜 - 博客园 在win下使用GIT dotNet 自带线程池与HTTP访问的若干疑问 解决"the database principal owns a schema in the database and cannot be dropped"问题
EditText获得焦点后,如何关闭软键盘
清炒白菜 · 2011-09-20 · via 博客园 - 清炒白菜

2011-09-20 23:01  清炒白菜  阅读(754)  评论()    收藏  举报

EditText获得焦点后, 会自动打开软键盘,这时候想让“EditText失去焦点,并关闭软键盘”, 暂时还没有找到完美的解决方案,因为EditText失去焦点功能未能完美实现。

所以采用了OnTouch Activity上某个大块控件,强制关闭软键盘的方法。

getListView().setOnTouchListener(new OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

hideSoftKeyboard();

return false;

}

});

private void hideSoftKeyboard(){

InputMethodManager inputManger = (InputMethodManager) getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE);

if(inputManger != null){

inputManger.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);

}

}

getListView()可以改成任意其他需要做事件绑定的控件对象。