共用方式為


Android 上的軟式鍵盤輸入模式

這個 Android 平臺專用是用來設定軟式鍵盤輸入區域的作業模式,並且藉由將附加屬性設定 Application.WindowSoftInputModeAdjust 為 列舉值 WindowSoftInputModeAdjust ,以在 XAML 中取用:

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

或者,您可以使用 Fluent API 從 C# 取用它:

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

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

方法 Application.On<Android> 會指定此平台專屬只會在Android上執行。 命名空間 Application.UseWindowSoftInputModeAdjust 中的 Xamarin.Forms.PlatformConfiguration.AndroidSpecific 方法可用來設定軟式鍵盤輸入區域作業模式,而 WindowSoftInputModeAdjust 列舉提供兩個值: PanResize。 值 Pan 會使用 AdjustPan 調整選項,當輸入控件具有焦點時,不會調整視窗的大小。 相反地,視窗的內容會進行流覽,讓目前的焦點不會被軟式鍵盤遮蔽。 值 Resize 會使用 AdjustResize 調整選項,這個選項會在輸入控件有焦點時調整視窗大小,讓軟式鍵盤騰出空間。

結果是,當輸入控件有焦點時,可以設定軟式鍵盤輸入區域操作模式:

軟式鍵盤操作模式平臺特定