• Android PopupWindow中EditText获取焦点自动弹出软键盘


    公司的项目中要求在点击搜索的时候弹出一个搜索框,搜索框中有一个EditText,用于数据搜索关键字,要求在弹出PopupWindow的时候自动弹出软键盘,原以为只要写上着两行代码可以搞的问题:

    1 InputMethodManager inputMethodManager=(InputMethodManager) et_search_key.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    2 inputMethodManager.showSoftInput(et_search_key, 0);

    在运行调试的时候,问题来了,没有按照设想的那样,显示软键盘。接下来就是找资料,试了好多方法,就是不行,最后使用Handler异步成功了。下面贴出代码:

     1 private void showSoft(){
     2         Handler handle=new Handler();
     3         handle.postDelayed(new Runnable() {
     4             
     5             @Override
     6             public void run() {
     7                 InputMethodManager inputMethodManager=(InputMethodManager) et_search_key.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
     8                 inputMethodManager.showSoftInput(et_search_key, 0);
     9             }
    10         }, 0);
    11     }
  • 相关阅读:
    html 中 url、scr、href、rel、rev
    MIME 和文件扩展名
    视频文件的容器格式和编码格式
    原型与原型链
    属性特征
    可选参数
    函数的定义(函数是值)
    闭包
    实现异步加载js文件及加载完成后回调
    前端工程打开速度优化的循序渐进总结
  • 原文地址:https://www.cnblogs.com/wangpf/p/4211411.html
Copyright © 2020-2023  润新知