【发布时间】:2016-12-04 19:00:16
【问题描述】:
所以,我在我创建的自定义工具栏下方有一个 EditText。在edittext下,有一个listview。但是,当软键盘出现时,用户无法看到该列表,因为它被键盘挡住了。当出现软键盘时,如何将 EditText 移动到屏幕顶部将工具栏推出屏幕我正在使用 NoActionBar 主题任何帮助将不胜感激。
编辑:我已经试过了
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"吗?
-
是的,我有。没有效果。
-
请附上您的视图层次结构。
-
好的。立即行动
-
已添加。请检查。
标签: android android-layout android-toolbar