The confused Android soft keyboard

In Android soft keyboard, there is no dismiss button like iOS keyboard. When we want to use a big Editor control in Xamarin Forms pages, we should consider the keyboard will convert the page drama, like this.

It’s terrible that users could not find a way to click the “DONE” button(Actually, if user click the title bar, the keyboard will be hidden, but I believe lots of users do not know this.)

How to solve this problem?

Generally speaking, we can resize the page, when keyboard appears.
We can set “WindowSoftInputMode = SoftInput.AdjustResize” to MainActivity. But there is a problem, all the Xamarin pages are based on a single MainActivity. It means that if we change this, every pages will be resized when keyboard appears. It’s fine, but sometimes some pages like search login etc, which contains one or two Entries, these pages we don’t want them to be resized.

So How to solve this problem again?


I try to search solutions, which I just want to resize one pages in Xamarin Forms on Android, not all pages. I found a thread here
It cannot work, I have put them into PageRenderer. It did resize the page, but the new size is incorrectly.

I try to use TextView ImeOpt property. It can hide the keyboard, but if I set this, the Editor control cannot contain the multi-line text. It’s so funny.

Finally, I found the solution. One day, I just read the Android documents, and found

adjustUnspecified It is unspecified whether the activity’s main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the current focus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window’s contents visible within a smaller area.

This is the default setting for the behavior of the main window.

This is the default settings for MainActivity. It said a layout can scroll their content.

OH,

How about put Editor into a ScrollView, like

mainGrid.Children.Add (new ScrollView { Content = textEditor}, 0, 1);

 

Yes, this solve my problem

Nexus 5 (Lollipop) Screenshot 3

Advertisements