Mehmet
Mehmet

Reputation: 755

page not scrolled when clicked input and display keyboard in webview xamarin forms

I try to develop android apps using Xamarin Forms. There is an input in a webview.When clicked the input , keyboard is displayed.But i can not see what i write.Input is not scrolled up.

XAML and WebViewRenderer contents as below.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:deneme"
         ">
<ContentPage.Content>
    <ScrollView>
        <Grid>
            <Grid.ColumnDefinitions>.ColumnDefinitions>
            <Grid.RowDefinitions>.RowDefinitions>
            <local:HybridWebView x:Name="webView" Grid.Row="0" Grid.ColumnSpan="2">
            </local:HybridWebView>
            <Button Text="Button1" Grid.Column="0" Grid.Row="1"/>
            <Button Text="Button2"/>
            <Label Text="Hidden"/>
        </Grid>
    </ScrollView>
</ContentPage.Content>

public class HybridWebViewRenderer : ViewRenderer<HybridWebView, Android.Webkit.WebView>
{

    Context _context;

    public HybridWebViewRenderer(Context context) : base(context)
    {
        _context = context;
    }

    protected override void OnElementChanged(ElementChangedEventArgs<HybridWebView> e)
    {
        base.OnElementChanged(e);

        if (Control == null)
        {
            var webView = new Android.Webkit.WebView(_context);
            webView.ScrollBarFadeDuration = 0;
            webView.Settings.JavaScriptEnabled = true;
            webView.SetWebViewClient(new JavascriptWebViewClient($"javascript: {JavascriptFunction}"));
            SetNativeControl(webView);
        }
    }
}

In order to set html input position prior keyboard,what should i do ?

Upvotes: 2

Views: 1034

Answers (3)

nevermore
nevermore

Reputation: 15816

You can use Soft Keyboard Input Mode on Android described in the document.

In xaml:

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

Or in code behind:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
...

App.Current.On<Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);

Refer: keyboard-hides-textarea-inside-a-hybrd-webview-in-xamarin-forms

Upvotes: 2

Saamer
Saamer

Reputation: 5109

Just add this line to your code

Window.SetSoftInputMode(SoftInput.AdjustPan);

Upvotes: 0

Raimo
Raimo

Reputation: 1536

Take a look here in the Android docs and especially the android:windowSoftInputMode (docs) attribute of activity.

Upvotes: 0

Related Questions