Giter VIP home page Giter VIP logo

keyboard's Introduction

keyboard's People

Contributors

leavesczy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

keyboard's Issues

部分手机中存在虚拟键盘(且可以手动关闭开启),会存在闪跳问题

我们这边采用了这种方式去获取软键盘:楼主可以试一下,做到存在虚拟键盘可以关闭,一些刘海屏的时候做到无缝切换。
代码:
/**
* 获取键盘的高度
*/
private int getSoftKeyboardHeight() {
Rect rect = new Rect();
mWindow.getDecorView().getWindowVisibleDisplayFrame(rect);
// 屏幕真实高度
int realHeight = mWindow.getDecorView().getRootView().getHeight();
// 虚拟键高度 ,遍历DecorView ViewTree 下的唯一子布局LinearLayout
// 获取对应的bottomMargin 即可得到对应软键盘的高度,0为关闭了虚拟键盘
int navigationBarHeight = 0;
try {
ViewGroup decorView = (ViewGroup) mWindow.getDecorView();
int childCount = decorView.getChildCount();
for (int i = 0; i < childCount; i++) {
View childAt = decorView.getChildAt(i);
if (childAt instanceof LinearLayout) {
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) childAt.getLayoutParams();
navigationBarHeight = layoutParams.bottomMargin;
}
}
} catch (Exception e) {
e.printStackTrace();
}
// 用于计算键盘高度
int softInputHeight = realHeight - navigationBarHeight - rect.bottom;
Log.e(TAG, "------------------------------------");
Log.e(TAG, "realHeight:" + realHeight);
Log.e(TAG, "navigationBarHeight: " + navigationBarHeight);
Log.e(TAG, "displayBottom:" + rect.bottom);
Log.e(TAG, "softInputHeight:" + softInputHeight);
if (softInputHeight > 0) {
// 因为考虑到用户可能会主动调整键盘高度,所以只能是每次获取到键盘高度时都将其存储起来
mSharedPreferences.edit().putInt(KEY_SOFT_KEYBOARD_HEIGHT, softInputHeight).apply();
}
return softInputHeight;
}

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.