Giter Site home page Giter Site logo

softkeyboardutil's Introduction

通过一行代码实现软键盘与EditText的交互.

介绍 : 有一个很常见的需求,就是页面中软键盘打开时,希望能点击屏幕其他的任何位置,就能把软键盘给隐藏掉.

比如登录, 注册之类的常见页面.

在实际开发中,很多大佬通过其他控件的点击事件,在onclick方法中调用软键盘的隐藏方法.

在页面复杂的时候,要实现的onclick方法会很多,甚至还会有逻辑处理冲突的情况.这样做就显得非常不友好.


原理 : 怎样封装成一行代码实现,就是重写Activity的dispatchTouchEvent(MotionEvent ev)方法,全局监听触摸事件, 当点击的页面时,发现如果焦点在EditView上,就把软键盘隐藏,否则就不做处理.

使用: 只要改变return的返回值即可

@Override
public View[] filterViewByIds() {
       return 传入要过滤的View[]
}

@Override
public int[] hideSoftByEditViewIds() {
   
    return 传入页面EditText的id[]
}

修复bug: 修复连续点击EditText,软键盘会先关闭在打开的问题


效果 :

图片


喜欢的朋友记得点个Star 具体详情请看文件 博客地址

softkeyboardutil's People

Contributors

zybieku avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.