如题,我需要在一个应用中软键盘弹出和隐藏的时侯去做一些的操作,现在问题是如何可以捕获的到这两个事件呢??
我按网上提供最多的一种方法:【在androidManifest.xml里面定义:android:configChanges="orientation| keyboardHidden",然后在activity里面继承onConfigurationChanged的方法,处理上面的两个消息就OK了。 】去做了,但是当键盘弹出或者隐藏时,程序却压根没有去运行onConfigurationChanged,只有当横竖屏切换时才有运行。
跪求各位达人,这是什么原因啊?还有其他方法可以实现我的需求吗??
谢谢!!
我按网上提供最多的一种方法:【在androidManifest.xml里面定义:android:configChanges="orientation| keyboardHidden",然后在activity里面继承onConfigurationChanged的方法,处理上面的两个消息就OK了。 】去做了,但是当键盘弹出或者隐藏时,程序却压根没有去运行onConfigurationChanged,只有当横竖屏切换时才有运行。
跪求各位达人,这是什么原因啊?还有其他方法可以实现我的需求吗??
谢谢!!
2. I think it's not a good ideal to deal View.onLayout, it will be called frequently.
3. I think deal the Activity.onWindowAttributeChange() is a better solution.
请问有办法吗?谢谢
// 目前的我的View为整个窗口大小, 如果不是可能要调整
// 希望对有些人有帮助或者提示左右,可能有更好的方法
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
int measuredHeight = MeasureSpec.getSize(heightMeasureSpec);
if(measuredHeight < getHeight() && input != null) { // 软键盘显示
// @input 为我自定义组件, input.mRightBY 为该组件的下边界
int distance = mInput.mRightBY - measuredHeight; // 计算滚动距离
if(distance > 0) {
scrollBy(0, distance); // 滚动
}
} else if(measuredHeight > getHeight()) { // 软键盘隐藏
scrollTo(0, 0); // 恢复
}
setMeasuredDimension(measuredWidth, measuredHeight);
}
public void onWindowAttributesChanged(LayoutParams params) {
// TODO Auto-generated method stub
super.onWindowAttributesChanged(params);
System.out
.println("......................................................");
}
这个方法只有在初始化activity中调用一次以后就不再调用了 怎么个问题呀