android窗口生命周期,Android 上的页面生命周期事件

Android 上的页面生命周期事件Page Lifecycle Events on Android

07/10/2018

本文内容

此 Android 平台特定用于对 Disappearing Appearing 使用 AppCompat 的应用程序分别禁用和页面事件。This Android platform-specific is used to disable the Disappearing and Appearing page events on application pause and resume respectively, for applications that use AppCompat. 此外,它还可以控制是否在恢复时显示软键盘(如果它在暂停时显示),前提是软键盘的操作模式设置为 WindowSoftInputModeAdjust.Resize 。In addition, it includes the ability to control whether the soft keyboard is displayed on resume, if it was displayed on pause, provided that the operating mode of the soft keyboard is set to WindowSoftInputModeAdjust.Resize.

备注

请注意,默认情况下将启用这些事件,以便为依赖于事件的应用程序保留现有行为。Note that these events are enabled by default to preserve existing behavior for applications that rely on the events. 禁用这些事件会使 AppCompat 事件周期与 AppCompat 事件周期匹配。Disabling these events makes the AppCompat event cycle match the pre-AppCompat event cycle.

xmlns:android="clr-namespace::::no-loc(Xamarin.Forms):::.PlatformConfiguration.AndroidSpecific;assembly=:::no-loc(Xamarin.Forms):::.Core" xmlns:androidAppCompat="clr-namespace::::no-loc(Xamarin.Forms):::.PlatformConfiguration.AndroidSpecific.AppCompat;assembly=:::no-loc(Xamarin.Forms):::.Core"

android:Application.WindowSoftInputModeAdjust="Resize"

androidAppCompat:Application.SendDisappearingEventOnPause="false"

androidAppCompat:Application.SendAppearingEventOnResume="false"

androidAppCompat:Application.ShouldPreserveKeyboardOnResume="true">

...

此外,还可以使用 Fluent API 从 c # 使用该方法:Alternatively, it can be consumed from C# using the fluent API:

using :::no-loc(Xamarin.Forms):::.PlatformConfiguration;

using :::no-loc(Xamarin.Forms):::.PlatformConfiguration.AndroidSpecific;

using :::no-loc(Xamarin.Forms):::.PlatformConfiguration.AndroidSpecific.AppCompat;

...

:::no-loc(Xamarin.Forms):::.Application.Current.On()

.UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize)

.SendDisappearingEventOnPause(false)

.SendAppearingEventOnResume(false)

.ShouldPreserveKeyboardOnResume(true);

Application.Current.On方法指定此平台特定的仅在 Android 上运行。The Application.Current.On method specifies that this platform-specific will only run on Android. [ Application.SendDisappearingEventOnPause ] (x: :::no-loc(Xamarin.Forms)::: 。PlatformConfiguration. :::no-loc(Xamarin.Forms)::: AndroidSpecific (。IPlatformElementConfiguration { :::no-loc(Xamarin.Forms)::: 。PlatformConfiguration :::no-loc(Xamarin.Forms)::: 。应用程序},即命名空间中的) # A3 方法, :::no-loc(Xamarin.Forms):::.PlatformConfiguration.AndroidSpecific.AppCompat 用于在 Disappearing 应用程序进入后台时启用或禁用触发页面事件。[ Application.SendAppearingEventOnResume ] (x: :::no-loc(Xamarin.Forms)::: 。PlatformConfiguration. :::no-loc(Xamarin.Forms)::: AndroidSpecific (。IPlatformElementConfiguration { :::no-loc(Xamarin.Forms)::: 。PlatformConfiguration :::no-loc(Xamarin.Forms)::: 。应用程序},) # A3 方法用于启用或禁用 Appearing 在应用程序从后台恢复页面事件时触发页面事件。The Application.SendAppearingEventOnResume method is used to enable or disable firing the Appearing page event, when the application resumes from the background. [ Application.ShouldPreserveKeyboardOnResume ] (x: :::no-loc(Xamarin.Forms)::: 。PlatformConfiguration. :::no-loc(Xamarin.Forms)::: AndroidSpecific (。IPlatformElementConfiguration { :::no-loc(Xamarin.Forms)::: 。PlatformConfiguration :::no-loc(Xamarin.Forms)::: 。应用程序},System.object) # A3 方法用于控制是否在恢复时显示软键盘(如果它是在暂停时显示的),前提是软键盘的操作模式设置为 WindowSoftInputModeAdjust.Resize 。The Application.ShouldPreserveKeyboardOnResume method is used control whether the soft keyboard is displayed on resume, if it was displayed on pause, provided that the operating mode of the soft keyboard is set to WindowSoftInputModeAdjust.Resize.

结果是,不会 Disappearing Appearing 在应用程序暂停并分别恢复时触发和页面事件,并且如果在应用程序暂停时显示软键盘,则当应用程序恢复时,也会显示该事件:The result is that the Disappearing and Appearing page events won't be fired on application pause and resume respectively, and that if the soft keyboard was displayed when the application was paused, it will also be displayed when the application resumes:

dbd651140293b00c553925cca79fb973.pngdbd651140293b00c553925cca79fb973.png

相关链接Related links

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值