android - How to hide footer component that appear on keyboard's top when editText gets focused in fragment?
问题描述
Actually the footer is set inside an activity class and the edittext is placed inside a fragment.
manifest file
<activity
android:name="HomeController"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden|adjustPan"/>
Inside my fragment class I added
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
These are the code snippet that I used, but it won't work!
Note: in Fragment UI, the whole screen has a scroll view,
Don't know why it is happening like this?Actually I don't want my footer on the keyboard's top.
Any suggestions on how to solve this behavior? And its appriciatble for the replies :)
解决方案
将此添加到您的活动中。
我没有测试,但这可能有效。虽然这是一个坏方法(
contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
View rootView = getWindow().getDecorView().getRootView();
rootView.getWindowVisibleDisplayFrame(r);
int screenHeight = rootView.getHeight();
// r.bottom is the position above soft keypad or device button.
// if keypad is shown, the r.bottom is smaller than that before.
int keypadHeight = screenHeight - r.bottom;
Log.d(TAG, "keypadHeight = " + keypadHeight);
if (keypadHeight > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height.
// keyboard is opened
//set bottom navigation(footer) bar to View.GONE
}
else {
// keyboard is closed
//set bottom navigation bar(footer) to View.VISIBLE
}
}
});
推荐阅读
- c# - 将 XDocument 中的嵌套类遍历到 JSON
- postgresql - 链接两个卷,容器未启动
- sql - 在 SQL 中使用 MINUS 子句的问题
- python - 在巨大的 1 和 0 列表中提取 1 密集区域的边界
- javascript - ESLint 使用未使用变量破坏数组的规则
- ios - 使用 Storyboard 从 XIB 加载 UIView - 视图的属性为零
- angular - 使用表单数组重置的角度表单清除表单数组值
- memory - tkinter partial 和 lambda 命令导致内存泄漏
- java - BigQuery 分页 - 使用 pageToken 或 startIndex?
- r - 自定义缩放轴后ggplot2缺少标签