{"id":13645049,"url":"https://github.com/zybieku/SoftKeyboardUtil","last_synced_at":"2025-04-21T11:32:41.562Z","repository":{"id":110945123,"uuid":"91902093","full_name":"zybieku/SoftKeyboardUtil","owner":"zybieku","description":"一行代码实现Android软键盘和EditText各种交互","archived":false,"fork":false,"pushed_at":"2018-12-22T10:13:24.000Z","size":578,"stargazers_count":488,"open_issues_count":3,"forks_count":61,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-11-09T17:42:56.241Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zybieku.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-05-20T16:31:08.000Z","updated_at":"2024-09-24T03:06:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"6d497e69-e965-40f0-a83f-bf0385d644e3","html_url":"https://github.com/zybieku/SoftKeyboardUtil","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zybieku%2FSoftKeyboardUtil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zybieku%2FSoftKeyboardUtil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zybieku%2FSoftKeyboardUtil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zybieku%2FSoftKeyboardUtil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zybieku","download_url":"https://codeload.github.com/zybieku/SoftKeyboardUtil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250048029,"owners_count":21366162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:02:24.550Z","updated_at":"2025-04-21T11:32:41.527Z","avatar_url":"https://github.com/zybieku.png","language":"Java","readme":"\n## 通过一行代码实现软键盘与EditText的交互.\n\n\u003e **介绍 :** \n \u003e有一个很常见的需求,就是页面中软键盘打开时,希望能**点击屏幕其他的任何位置,就能把软键盘给隐藏掉.**  \n\n \u003e比如登录, 注册之类的常见页面. \n\n \u003e在实际开发中,很多大佬通过其他控件的点击事件,在onclick方法中调用软键盘的隐藏方法.\n\n \u003e在页面复杂的时候,要实现的onclick方法会很多,甚至还会有逻辑处理冲突的情况.这样做就显得非常不友好. \n\n\n----------\n#### 方式一 继承方式\n\n\u003e **原理 :** 怎样封装成一行代码实现,就是重写Activity的dispatchTouchEvent(MotionEvent ev)方法,全局监听触摸事件, 当点击的页面时,发现如果焦点在EditView上,就把软键盘隐藏,否则就不做处理.\n\n\u003e**使用:** 只要对应的页面 重写下面一个方法,改变return的返回值即可\n ```\n    @Override\n    public int[] hideSoftByEditViewIds() {\n        return 传入页面EditText的id[]\n    }\n ```\n\u003e 如果要对某些控件进行过滤 ,可以重写\n   ```\n      @Override\n    public View[] filterViewByIds() {\n           return 传入要过滤的View[]\n    }\n   ```\n#### 方式二  proxy链式调用(由jiiiiiin提供)\n\n```\n      try {\n            mActivityKeyBoardProxy = ActivityKeyBoardProxyBuild.getInstance()\n                    .withActivity(this)\n                    .withHideSoftByEditViewIds(new int[]{R.id.et_phone, R.id.et_check_code, R.id.et_city_code})\n                    .withFilterViewByIds(new View[]{mBtnCode})\n                    .withOnHideInputForceListener(new ActivityKeyBoardProxy.OnHideInputForceListener() {\n                        @Override\n                        public void onHideInputForce(MotionEvent motionEvent) {\n                            Log.d(TAG, \"隐藏了系统键盘\");\n                        }\n                    })\n                    .build();\n        } catch (Exception e) {\n            e.printStackTrace();\n            Log.e(TAG, e.getMessage());\n        }\n```\n\n----------\n\u003e**修复bug:** \n   修复连续点击EditText,软键盘会先关闭在打开的问题\n----------\n\u003e **效果 :** \n\n![图片](https://github.com/zybieku/SoftKeyboardUtil/blob/master/gif/GIF.gif)\n\n----------\n\u003e 由于半年多没写Android,很多代码陌生了,欢迎各位大佬提pull request\n\n喜欢的朋友记得点个Star\n具体详情请看主页\n[博客地址](http://blog.csdn.net/zybieku/article/details/68925116)\n\n\n\n","funding_links":[],"categories":["软键盘"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzybieku%2FSoftKeyboardUtil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzybieku%2FSoftKeyboardUtil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzybieku%2FSoftKeyboardUtil/lists"}