問題概況:橫板cocos2dx游戲,點擊輸入框彈出鍵盤時,界面要求跟隨網上平易,不能擋住輸入框。這種問題只出現在非全屏鍵盤到情況下。
方案1:mainActivity重寫onconfigurationChanged,監聽屏幕方向旋轉,添加Android:configChanges="orientation|keyboard"。
缺點全屏下無效,如果設置為非全屏,
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />,去掉Fullscreen
這樣會顯示系統狀態欄。否掉!
方案2:彈出鍵盤時勢必引起layout布局的變化,監聽布局的變化然后計算偏移,即可算出是否時顯示或隱藏鍵盤。
//獲取rootview
mRoot =
this.getWindow().getDecorView();
全局鍵盤顯示和隱藏不會觸發
//添加布局變化監聽
root.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect rect = new Rect();
root.getWindowVisibleDisplayFrame(rect);
int rootInvisibleHeight =root.getRootView().getHeight() - rect.bottom;
if (rootInvisibleHeight<= 100) {
//通知c++做想做的事
hideKeyBoardHandler();
} else {
showKeyBoardHandler();
}
}
});
以上!另外對APP進行在線全方位的安全性、兼容性測試,我都會用這個:www.ineice.com。