├── .gitignore ├── .idea └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── keyboard │ │ └── test │ │ └── MainActivity.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── doc ├── image1.png └── image2.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── libs ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── keyboard │ │ └── monitor │ │ ├── InputEditText.java │ │ ├── KeyboardHelper.java │ │ ├── KeyboardInputConnection.java │ │ ├── OnKeyboardListener.java │ │ └── OnKeyboardRetractListener.java │ └── res │ └── values │ └── strings.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KeyboardMonitor 2 | Probably the best keyboard monitor on the github. 3 | 4 | 大概是全网最好的键盘监听了. 5 | 6 | The android keyboard listener listens for keyboard height to show or hide. 7 | 8 | 安卓 键盘监听器 监听键盘高度跟显示or隐藏. 9 | 10 | It can be registered in dialog and popupWindow. It can accurately recognize the status of the pop-up keyboard and accurately obtain the height of the current keyboard. It is compatible with full screen status, hiding or enabling virtual navigation keys, dynamically changing dp and other emergencies. 11 | 12 | 可以在dialog跟popupWindow中注册使用。能够准确的识别弹出键盘状态以及准确获取当前键盘的高度,兼容全屏状态、隐藏或启用虚拟导航键、动态改变dp等突发状况。 13 | 14 | Step 1. Add the JitPack repository to your build file 15 | 16 | Add it in your root build.gradle at the end of repositories: 17 | 18 | allprojects { 19 | repositories { 20 | ... 21 | maven { url 'https://jitpack.io' } 22 | } 23 | } 24 | Step 2. Add the dependency 25 | 26 | dependencies { 27 | implementation 'com.github.fengxiaocan:KeyboardMonitor:v1.1.3' 28 | } 29 | 30 | eg: 31 | 32 | KeyboardHelper.registerKeyboardListener(getWindow(),new OnKeyboardListener(){ 33 | @Override 34 | public void onKeyBoardEvent(boolean isShow,int height){ 35 | 36 | } 37 | }); 38 | 39 | ![avatar](/doc/image1.png) 40 | ![avatar](/doc/image2.png) 41 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.3" 6 | defaultConfig { 7 | applicationId "com.keyboard.test" 8 | minSdkVersion 16 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'androidx.appcompat:appcompat:1.1.0' 25 | implementation project(path: ':libs') 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/keyboard/test/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.keyboard.test; 2 | 3 | import android.os.Bundle; 4 | import android.util.Log; 5 | import android.view.View; 6 | import android.view.ViewTreeObserver; 7 | import android.view.Window; 8 | import android.view.WindowManager; 9 | import android.widget.Button; 10 | import android.widget.EditText; 11 | import android.widget.LinearLayout; 12 | import android.widget.TextView; 13 | 14 | import androidx.appcompat.app.AlertDialog; 15 | import androidx.appcompat.app.AppCompatActivity; 16 | 17 | import com.keyboard.monitor.KeyboardHelper; 18 | import com.keyboard.monitor.OnKeyboardListener; 19 | 20 | public class MainActivity extends AppCompatActivity{ 21 | private TextView tvPan; 22 | private EditText etInput; 23 | private Button btAdd; 24 | private LinearLayout layout; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState){ 28 | requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏 29 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 30 | WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏 31 | 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_main); 34 | initView(); 35 | OnKeyboardListener listener=new OnKeyboardListener(){ 36 | @Override 37 | public void onKeyBoardEvent(boolean isShow,int height){ 38 | if(isShow){ 39 | tvPan.setVisibility(View.GONE); 40 | } else{ 41 | if(height>0){ 42 | tvPan.setText("Keyboard Height:"+height); 43 | tvPan.getLayoutParams().height=height; 44 | tvPan.setVisibility(View.VISIBLE); 45 | } 46 | } 47 | } 48 | }; 49 | 50 | KeyboardHelper.registerKeyboardListener(this,listener); 51 | } 52 | 53 | private void initView(){ 54 | tvPan = findViewById(R.id.tv_pan); 55 | etInput = findViewById(R.id.et_input); 56 | btAdd = findViewById(R.id.bt_add); 57 | layout = findViewById(R.id.layout); 58 | btAdd.setOnClickListener(new View.OnClickListener(){ 59 | @Override 60 | public void onClick(View v){ 61 | new AlertDialog.Builder(MainActivity.this).setTitle("TITLE").setMessage("message").show(); 62 | } 63 | }); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 |