Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to adapt a layout when the keyboard is shown?

I would like to "instruct" android how to correctly adapt the screen layout when the user does something that pops up the keyboard.

Actually the when the keyboard is shown android simple draws it over the bottomest items of the screen. Although it is a simple and, sometimes, correct approach

in some circunstances it goes pretty bad. For example if the inputtext being typed is the bottomest item of the screen... the keyboard will simple cover it and the user will lost the information about what he is typing.

another scenario is when the keyboard covers only partially some item, then android runs into a crazy state where the screen gets unstable

enter image description here

the image doesn't show, but these two partially covered buttons are blinking like crazy when the keyboard pops up

So again the question is... how can i tell android which layout items it can shrink, or simple remove from screen, in order to create space to display the keyboard?

=================UPDATE==============

I think this whole keyboard layout situation has 2 possible "best scenarios":
1- the information i want to show user is on top of screen so i would like the keyboard cover the bottom
2- the information i want to show is ont bottom so i want the keyboard "push" the screen up so the user can see what is on bottom like the next photo

enter image description here

the ideal solution is not an "app wide" configuration since the behavior should be chose layout by layout

like image 981
Rafael Lima Avatar asked Dec 31 '25 04:12

Rafael Lima


2 Answers

Use

android:windowSoftInputMode="adjustPan"

And at your screen you set the root to be a ScrollView with android:fitSystemView="true"

Also set your button that is below from edittext to focusable and focusableInTouchMode to true.

like image 169
Marcos Vasconcelos Avatar answered Jan 01 '26 16:01

Marcos Vasconcelos


you can add this line to your manifest (in your activity tag)

android:windowSoftInputMode="adjustPan|adjustResize"

this will scroll the views so this way soft keyboard wont covers the view,

but i dont know if you could specifically tell android which items to cover...

like image 43
Mohamad Rostami Avatar answered Jan 01 '26 18:01

Mohamad Rostami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!