简体   繁体   English

键盘关闭后Android操作栏消失

[英]Android action bar disappearing after keyboard close

Here's how the situation looks like. 这是情况的样子。 在此输入图像描述

And my layout file is like: 我的布局文件如下:

<RelativeLayout>  # Parent
  <RelativeLayout> # Camera preview
  </RelativeLayout>
  <LinearLayout>   # Bottom bar
  </LinearLayout>
</RealtiveLayout>

I understand Android adds/removes views by evaluating whether they are within the view area but I haven't been able to fix this by any means so far. 我了解Android通过评估它们是否在视图区域内来添加/删除视图,但到目前为止我无法通过任何方式解决这个问题。

Using android:windowSoftInputMode="adjustResize" to ensure Actionbar is always visible isn't doable as that spoils the aspect ratio of camera preview above. 使用android:windowSoftInputMode="adjustResize"来确保Actionbar始终可见是不可行的,因为它破坏了上面相机预览的宽高比。

See ActionBarSherlock actionbar disappears when focus changes from EditText to Button 当焦点从EditText更改为Button时,请参阅ActionBarSherlock操作栏消失

For those of you who can't switch to adjustResize . 对于那些无法切换到adjustResize I noticed that actionbar is reappearing after the screen is turned off and on again, so I solved it with this hack: 我注意到屏幕关闭再打开后再次出现操作栏,所以我用这个黑客解决了它:

dialog.setOnDismissListener(dialog1 -> {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        handler.postDelayed(() -> {
            activity.findViewById(android.R.id.content).requestLayout();
        }, 600);
    }
})

This code requests redraw of the whole hierarchy approximately after the keyboard has settled. 此代码在键盘结算后大约请求重绘整个层次结构。 The checked SDK version and the delay value may be lower, but I decided to play safe. 检查的SDK版本和延迟值可能会更低,但我决定安全地玩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM