有空再来重新编辑。先贴上代码块
private int mStatusHeight;
private int cKeyBoardHeight;@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
int i = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (i > 0)
mStatusHeight = getResources().getDimensionPixelSize(i);
initKeyBoard();
mHandler.postDelayed(new Runnable()
{
public void run()
{
showKeyboard(mTextEditor);
}
}
, 400L);
}
private void initKeyBoard() {
final View localView = findViewById(R.id.compose_message);//activity的根view_group
localView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout()
{
Rect localRect = new Rect();
localView.getWindowVisibleDisplayFrame(localRect);
int i = localView.getRootView().getHeight()
- (localRect.bottom - localRect.top) - mStatusHeight;
Log.v("533", " cKeyBoardHeight=" + cKeyBoardHeight);
if (cKeyBoardHeight != i)
{
cKeyBoardHeight = i;
if (i > 0)
{
getWindow().setSoftInputMode(32);
}
}
}
});
}
V/533 (29642): cKeyBoardHeight=0
V/533 (29642): cKeyBoardHeight=0
V/533 (29642): cKeyBoardHeight=0
V/533 (29642): cKeyBoardHeight=585
V/533 (29642): cKeyBoardHeight=585
V/533 (29642): cKeyBoardHeight=0
V/533 (29642): cKeyBoardHeight=0
V/533 (29642): cKeyBoardHeight=0
V/533 (29642): cKeyBoardHeight=0