Reputation: 755
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
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
Reputation: 5109
Just add this line to your code
Window.SetSoftInputMode(SoftInput.AdjustPan);
Upvotes: 0