lia*_*ang 6 android android-softkeyboard
我知道我可以使用"android:windowSoftInputMode ="adjustPan"做一些自动偏移.但我真的想得到一些特殊用途的软件键盘高度.
我发现这里有类似的话题:获得软键盘的尺寸.但显然,它不是一个通用的解决方案.
是否有通用方法或内置方法来获得软键盘高度?(或者如何获得当前光标位置和软件键盘顶部位置之间的偏移值?)
非常感谢
这是我的解决方案,它也很hacky,但解决了问题。
android:windowSoftInputMode="adjustResize"在清单中的活动标记中添加了标志,如@bill 建议的那样。现在主要故事在onGlobalLayout()。y axis在那里我计算了临时视图和高度之间的差异root view
final View view = findViewById(R.id.base);
view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int rootViewHeight = view.getRootView().getHeight();
View tv = findViewById(R.id.temp_view);
int location[] = new int[2];
tv.getLocationOnScreen(location);
int height = (int) (location[1] + tv.getMeasuredHeight());
deff = rootViewHeight - height;
// deff is the height of soft keyboard
}
});
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
8837 次 |
| 最近记录: |