Xamarin Forms 2.0 AppCompat android键盘模式
Xamarin I更新至版本4、表单和2.0版本。在Android上,我使用AppCompat 我有个问题。以前,Android键盘导致调整视图大小。现在这种情况没有发生。键盘显示在俯视图上。以及要隐藏的所需元素 我试过:Xamarin Forms 2.0 AppCompat android键盘模式,xamarin,android-softkeyboard,xamarin.forms,android-appcompat,Xamarin,Android Softkeyboard,Xamarin.forms,Android Appcompat,Xamarin I更新至版本4、表单和2.0版本。在Android上,我使用AppCompat 我有个问题。以前,Android键盘导致调整视图大小。现在这种情况没有发生。键盘显示在俯视图上。以及要隐藏的所需元素 我试过: [Activity(WindowSoftInputMode = SoftInput.AdjustResize, Label = "Title", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher =
[Activity(WindowSoftInputMode = SoftInput.AdjustResize, Label = "Title", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
ToolbarResource = Resource.Layout.toolbar;
TabLayoutResource = Resource.Layout.tabs;
LoadApplication(new App());
Window.DecorView.SetFitsSystemWindows(true);
}
}
已在本课上制作了Daylight AppCompat:
谢谢。我已经解决了这个问题。反编译类 “Forms AppCompativeActivity”,并观察该方法在创建时的工作方式 因此,我产生了以下代码:
[Activity(Label = "Title", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Window.SetSoftInputMode(SoftInput.AdjustResize);
AndroidBug5497WorkaroundForXamarinAndroid.assistActivity(this);
ToolbarResource = Resource.Layout.toolbar;
TabLayoutResource = Resource.Layout.tabs;
LoadApplication(new App());
}
public class AndroidBug5497WorkaroundForXamarinAndroid
{
// For more information, see https://code.google.com/p/android/issues/detail?id=5497
// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.
// CREDIT TO Joseph Johnson (http://stackoverflow.com/users/341631/joseph-johnson) for publishing the original Android solution on stackoverflow.com
public static void assistActivity(Activity activity)
{
new AndroidBug5497WorkaroundForXamarinAndroid(activity);
}
private Android.Views.View mChildOfContent;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams;
private AndroidBug5497WorkaroundForXamarinAndroid(Activity activity)
{
FrameLayout content = (FrameLayout)activity.FindViewById(Android.Resource.Id.Content);
mChildOfContent = content.GetChildAt(0);
ViewTreeObserver vto = mChildOfContent.ViewTreeObserver;
vto.GlobalLayout += (object sender, EventArgs e) => {
possiblyResizeChildOfContent();
};
frameLayoutParams = (FrameLayout.LayoutParams)mChildOfContent.LayoutParameters;
}
private void possiblyResizeChildOfContent()
{
int usableHeightNow = computeUsableHeight();
if (usableHeightNow != usableHeightPrevious)
{
int usableHeightSansKeyboard = mChildOfContent.RootView.Height;
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
frameLayoutParams.Height = usableHeightSansKeyboard - heightDifference;
mChildOfContent.RequestLayout();
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight()
{
Rect r = new Rect();
mChildOfContent.GetWindowVisibleDisplayFrame(r);
if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
{
return (r.Bottom - r.Top);
}
return r.Bottom;
}
}
}
[活动(Label=“Title”,Icon=“@drawable/Icon”,Theme=“@style/MyTheme”,MainLauncher=true,ConfigurationChanges=ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
公共类MainActivity:全局::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
全局::Xamarin.Forms.Forms.Init(这个,bundle);
Window.SetSoftInputMode(软输入.调整大小);
AndroidBug5497 Xamariandroid.辅助性的解决方案(本);
ToolbarResource=Resource.Layout.toolbar;
TabLayoutResource=Resource.Layout.tabs;
加载应用程序(新应用程序());
}
公共类AndroidBug5497 XamarinAndroid的解决方法
{
//有关详细信息,请参阅https://code.google.com/p/android/issues/detail?id=5497
//要使用该类,只需对已设置其内容视图的活动调用assistativity()。
//归功于约瑟夫·约翰逊(http://stackoverflow.com/users/341631/joseph-johnson)用于在stackoverflow.com上发布原始Android解决方案
公共静态无效辅助性(活动)
{
新的AndroidBug5497 Xamarinandroid解决方案(活动);
}
私有Android.Views.View mChildOfContent;
私人使用高度;
私有FrameLayout.LayoutParams frameLayoutParams;
私有AndroidBug5497 Xamariandroid的变通方法(活动)
{
FrameLayout content=(FrameLayout)activity.findviewbyd(Android.Resource.Id.content);
mChildOfContent=content.GetChildAt(0);
ViewTreeObserver vto=mChildOfContent.ViewTreeObserver;
vto.GlobalLayout+=(对象发送方,事件参数e)=>{
可能ResizeChildOfContent();
};
frameLayoutParams=(FrameLayout.LayoutParams)mChildOfContent.LayoutParameters;
}
private void possiblyResizeChildOfContent()
{
int usableHeightNow=computeusableheightnow();
如果(usableHeightNow!=usableHeightPrevious)
{
int usableheightsanskiboard=mChildOfContent.RootView.Height;
int heightDifference=usableHeightSansKeyboard-usableHeightNow;
frameLayoutParams.Height=usableHeightSansKeyboard-heightDifference;
mChildOfContent.RequestLayout();
usableHeightPrevious=usableHeightNow;
}
}
私有int ComputersAbleLight()
{
Rect r=新的Rect();
mChildOfContent.GetWindowVisibleDisplayFrame(r);
if(Build.VERSION.SdkInt
在调用base.OnCreate(bundle)之后添加“Window.SetSoftInputMode(SoftInput.AdjustResize);”是很重要的 如果把这段代码放到Xamarin中就太好了。