leavesczy / keyboard Goto Github PK
View Code? Open in Web Editor NEW解决软键盘弹出和收缩时表情面板切换跳闪的问题
解决软键盘弹出和收缩时表情面板切换跳闪的问题
效果还不错,希望继续完善
我们这边采用了这种方式去获取软键盘:楼主可以试一下,做到存在虚拟键盘可以关闭,一些刘海屏的时候做到无缝切换。
代码:
/**
* 获取键盘的高度
*/
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;
}
如题
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.