Here is an interesting problem. Let’s say you are in a particular view, and you want to be able to set a background. You simple use the
View.setBackgroundDrawable(Drawable) call to do this. However once you do this, you realize that whenever the soft keyboard is opened it pushes your view to the top/resizes it such that your background looks squished.
I encountered this while working on a chatting application. The resulting image looks something like this:
The solution is quite simple:
- In your Activity Manifest, declare the activity which houses the view to
- Then follow this piece of code:
1 2 3 4 5
This will make sure that you set your background with the
Gravity.TOP which will ensure it is always aligned with the top of the container view and is not affected by the Soft Keyboard display.