Debasish
Debasish

Reputation: 457

Keyboard hides Textarea inside a Hybrd Webview in Xamarin forms

In xamarin forms I am making use of hybrid webview to display texarea and entry fields.When I try to enter some data inside the textarea the keyboard pops up and hides the textarea.
Thus I am not able to see the text that i'm typing.It does not auto scroll to the current cursor position.I have read that adding
android:windowSoftInputMode="adjustResize" to the android manifest file does the trick.
But is it possible to apply the above property to only the webview(without applying for other views)?Or is there any other way to auto scroll the view so that entry field(cursor)is just above the keyboard.
Please help

Upvotes: 4

Views: 3570

Answers (4)

Luis Palma
Luis Palma

Reputation: 11

Reviewing the documentation at https://learn.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/consuming/android#setting-the-soft-keyboard-input-mode

I think it's better to use:

<Application ...
    xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
    android:Application.WindowSoftInputModeAdjust="Resize">
    ...
</Application>

Upvotes: 1

David Clarke
David Clarke

Reputation: 13266

In App.xaml.cs you can add:

using AndroidSpecific = Xamarin.Forms.PlatformConfiguration.AndroidSpecific;

public App()
{
    InitializeComponent();
    AndroidSpecific.Application.SetWindowSoftInputModeAdjust(this, AndroidSpecific.WindowSoftInputModeAdjust.Resize);
    …

Which I guess is less idiomatic than Artūras Paleičikas' answer but achieves the same affect.

Upvotes: 12

Artūras Paleičikas
Artūras Paleičikas

Reputation: 629

What about:

protected override void OnCreate(Bundle savedInstanceState)
{
...

 global::Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>()
                .UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);

Upvotes: 3

Riyas
Riyas

Reputation: 495

Put your webview inside of a scroll view and handle the focused function , this help me in xamarin forms ios application.

  private void Handle_Focused(object sender, Xamarin.Forms.FocusEventArgs e)
  {
      SCr_View.ScrollToAsync(0, Web_View.Y * 50, false); // 50 is height u want to move up
  }

Try this up.

Upvotes: 0

Related Questions