因此,我在創建的自定義工具欄下方有一個EditText。在edittext中,有一個listview。但是,當軟鍵盤出現時,用戶看不到列表,因爲它被鍵盤阻擋。如何將EditText移動到屏幕頂部當軟鍵盤出現時將工具欄推出屏幕我正在使用NoActionBar主題任何幫助將不勝感激。Android - 當軟鍵盤出現時向上推動操作欄
編輯:我已經嘗試
android:windowSoftInputMode="adjustPan"
在Manifests.xml
謝謝!
編輯: 我使用此代碼來檢測鍵盤顯示時隱藏工具欄。
numbersActivityRoot = (CoordinatorLayout) findViewById(R.id.numbers_activity_root_view);
appBarLayout = (AppBarLayout) findViewById(R.id.appbarLayout);
numbersActivityRoot.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
numbersActivityRoot.getWindowVisibleDisplayFrame(r);
int heightDiff = numbersActivityRoot.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
Log.v("NUMBERS","Hide toolbar");
appBarLayout.setExpanded(false);
} else {
Log.v("NUMBERS","Show toolbar");
appBarLayout.setExpanded(true);
}
}
});
儘管日誌消息顯示檢測鍵盤的正確結果,但工具欄仍未隱藏。我究竟做錯了什麼?
你試過android:windowSoftInputMode =「adjustPan」嗎? –
是的,我有。沒有效果。 – Asym
請附上您的視圖層次結構。 –