【发布时间】:2016-04-05 07:20:23
【问题描述】:
我在 Android 上有一个 Xamarin.Forms 项目,我想使用“AdjustResize”作为处理软键盘的默认方法。我通过在OnCreate 中设置它来做到这一点:
[Activity(Label = "TestWhite.Droid", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar;
FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Window.SetSoftInputMode(SoftInput.AdjustResize);
LoadApplication(new App());
}
}
由于我已更新到AppCompat,AdjustResize 不适用于 API 22,但仍适用于 API 19。
使用仅包含一个页面的应用程序可以很容易地测试该问题,该页面包含滚动视图和页面底部的编辑器:
public MainPage()
{
InitializePage();
}
void InitializePage()
{
var editor = new Editor
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
HeightRequest = 200,
};
var tallLayout = new StackLayout
{
HorizontalOptions = LayoutOptions.FillAndExpand,
Orientation = StackOrientation.Horizontal,
HeightRequest = 450,
BackgroundColor = Color.Lime,
};
var layout = new StackLayout
{
Orientation = StackOrientation.Vertical,
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Children = { tallLayout, editor },
};
var scrollView = new ScrollView
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
scrollView.Content = layout;
Content = scrollView;
}
使用 API 19,当用户单击 Editor 时,视图会被向上推,以便用户可以看到他正在写的内容。相反,使用 API 22,键盘只出现在视图上,隐藏了 Editor。关于这种行为背后的原因有什么想法吗?
【问题讨论】:
标签: android xamarin android-appcompat xamarin-forms