zoukankan      html  css  js  c++  java
  • android之键盘转载

    显示键盘:
    EditText editText.setFocusable(true);
    editText.setFocusableInTouchMode(true);
    editText.requestFocus();
    InputMethodManager inputManager = (InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(editText, 0);

    首先要对指定的输入框请求焦点。然后调用输入管理器弹出软键盘。

    警告:对于刚跳到一个新的界面就要弹出软键盘的情况上述代码可能由于界面为加载完全而无法弹出软键盘。此时应该适当的延迟弹出软键盘如998毫秒(保证界面的数据加载完成)。实例
    [代码]java代码:

    Timer timer = new Timer();
    timer.schedule(new TimerTask(){
    public void run(){
    InputMethodManager inputManager = (InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(editText, 0);
    }
    }, 998);

    隐藏键盘:

    方法二:
    让EditText失去焦点,使用EditText的clearFocus方法
    例如:EditText edit=(EditText)findViewById(R.id.edit);
    edit.clearFocus();
    方法三:
    强制隐藏Android输入法窗口
    例如:EditText edit=(EditText)findViewById(R.id.edit);
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edit.getWindowToken(),0);
    警告:对于刚跳到一个新的界面就要弹出软键盘的情况上述代码可能由于界面为加载完全而无法关闭软键盘。此时应该适当的延迟弹出软键盘如998毫秒
    Timer timer = new Timer();
    timer.schedule(new TimerTask(){
    public void run(){
    EditText edit=(EditText)findViewById(R.id.edit);
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edit.getWindowToken(),0);
    }
    }, 998);
    方法四:EditText始终不弹出软件键盘
    例:EditText edit=(EditText)findViewById(R.id.edit);
    edit.setInputType(InputType.TYPE_NULL);

  • 相关阅读:
    win10 彻底删除mysql步骤
    IDEA中添加类的创建者信息
    针对标签中设置 disabled="true",$("#id").serialize()获取不到value的解决方法
    使用Vue-cli创建project遇到的坑
    Jmeter压测总结
    Java通过ssh远程连接服务器
    Django 学习笔记(一)
    Python 测试框架基础
    Python 基础&Excel操作
    Appium环境搭建及计算器小实验
  • 原文地址:https://www.cnblogs.com/wcLT/p/7698976.html
Copyright © 2011-2022 走看看