Android action bar disappears after closing keyboard
This is what the situation looks like.
And my layout file is like:
<RelativeLayout> # Parent
<RelativeLayout> # Camera preview
</RelativeLayout>
<LinearLayout> # Bottom bar
</LinearLayout>
</RealtiveLayout>
I understand that Android is adding / removing views by evaluating if they are in the viewport, but I still haven't been able to fix this.
Using android:windowSoftInputMode="adjustResize"
to ensure that the action bar is always visible is not feasible as it messes up the aspect ratio of the camera preview above.
source to share
See Action Bar ActionBarSherlock disappears when focus changes from EditText to button
For those of you who can't switch to adjustResize
. I noticed that the action bar reappears 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 asks to redraw the entire hierarchy after about the time the keyboard has settled. The tested SDK version and latency may be lower, but I decided to play safely.
source to share