因此,我在创建的自定义工具栏下方有一个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
请附上您的视图层次结构。 –