如何使 EditText 像 Google 保持应用程序一样工作(平滑滚动且不被输入法覆盖)?

how to make EditText work like Google keep app(smooth scroll and not covered by ime)?

我有一个带片段的 Activity,片段中有一个 EditText,我希望能够写几行文本,但 软件键盘覆盖了它EditText 增长时。

我见过 ScrollViewadjustResizeadjustPan 的用法,但我不知道为什么它们不起作用!

更新:

如果我使用 .beginTransaction().add 它工作正常但我需要使用 .beginTransaction().replace 和键盘盖 EditText

更新 2:

它在 android 4.3 上运行良好 但在 android 4.4 键盘盖中 EditText

我想要的:

  1. A layout(containing EditText) 出现时在键盘上方
  2. Smooth scroll 在该布局中

要强制显示软键盘,您可以使用

EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

要关闭它,您可以使用

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);

希望对您有所帮助。

根据 this answer,通过在根元素上设置 android:fitsSystemWindows="true" 它工作正常

使用半透明系统栏时出现了很多问题。我有一个类似的问题,我找到了 0 个解决方案。尝试去除半透明系统栏,看看是否正常。